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

Could someone explain me the output of "str("Hello") == str("World!")" in R. I was expecting "TRUE"

I’m just learning R, and I tried this:
str("Hello") == str("World!")

I was expecting an logical output, like TRUE or FALSE, but instead, it returned this:
chr "Hello" chr "World!" logical(0)

I didn’t understand why, bacause the str() function should print the class and whatever is inside parenthesis…
Could someone help me in understanding this, please?

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

Many thanks.

Tried: str("Hello") == str("World!")
Expected: "TRUE" or "FALSE"
Reality:
chr "Hello" chr "World!" logical(0)

>Solution :

See the following.

tmp <- str("Hello") 

print(tmp) 

is returning:

chr "Hello"
NULL

So you see that NULL is assigned to tmp. The same is for str("whatever").

So you are calling :

NULL == NULL

That’s obviously logical(0)

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