Evaluate expression given as a string

前端 未结 7 2000
小蘑菇
小蘑菇 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:00

    Alternatively, you can use evals from my pander package to capture output and all warnings, errors and other messages along with the raw results:

    > pander::evals("5+5")
    [[1]]
    $src
    [1] "5 + 5"
    
    $result
    [1] 10
    
    $output
    [1] "[1] 10"
    
    $type
    [1] "numeric"
    
    $msg
    $msg$messages
    NULL
    
    $msg$warnings
    NULL
    
    $msg$errors
    NULL
    
    
    $stdout
    NULL
    
    attr(,"class")
    [1] "evals"
    

提交回复
热议问题