I'm writing a function that catches conversion errors when a value is coerced to NA. It seems like the base conversion functions are inconsistent in returning warnings.
> as.numeric("a")
[1] NA
Warning message:
NAs introduced by coercion
However, the warning is not shown when converting to logical:
> as.logical("a")
[1] NA
My question: Is there a way to make the warning explicit when a string cannot be converted to logical?
I have looked into rlang::as_logical()
, but it returns an error instead of a warning, that I'd like to avoid if possible.