Evaluate expression given as a string

前端 未结 7 1913
小蘑菇
小蘑菇 2020-11-21 23:41

I\'m curious to know if R can use its eval() function to perform calculations provided by e.g. a string.

This is a common case:

eval(\"5         


        
7条回答
  •  执念已碎
    2020-11-22 00:14

    You can use the parse() function to convert the characters into an expression. You need to specify that the input is text, because parse expects a file by default:

    eval(parse(text="5+5"))
    

提交回复
热议问题