Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Coercing argument of type 'character' to logical" warning message for !any function

I run this code to see if in depth I have "0-5cm", it works but I also get a warning message that I don’t understand, anyone know?

if (isTRUE(!any(depth) %in% "0-5cm")) {print("yes")} else {print("no")}
[1] "yes"
Warning message:
In any(depth) : coercing argument of type 'character' to logical

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are mixing up your parenthesis.
If you want to asses your if condition you need something more like:

if(!any(depth %in% "0-5cm")) # looking for the many in the specific makes logically little sense, even if it works

Also not knowing how depth looks like, i assume it is a vector?
If this is the case I’d advise to turn your statement around to:

!any("0-5cm" %in% depth) # looking for the specific within the many
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading