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

Evaluate dynamic mathmatical functions

Say I have the below terms and operators

x <- 0
y <- '<'
z <- 1

and I have constructed this into a string:

paste(x, y, z)   # "0 < 1"

How do I then get R to evaluate this string to give TRUE?
I have tried eval which returns a character
tried parse which gives cannot open the connection

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

Thank you.

>Solution :

You could use eval and parse with text like this:

x <- 0
y <- '<'
z <- 1
eval(parse(text = paste(x,y,z)))
#> [1] TRUE

Created on 2023-02-13 with reprex v2.0.2

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