使用readline选择现有变量

时间:2014-10-02 13:09:53

标签: r user-interface

我想让我的脚本用户选择一个现有对象(矢量)。

我觉得这样的事情

...
message("Select a vector of y values")  
nwd <- readLines(n = 1)
return(mean(nwd))
...

但结果是 NA ,因为 nwd 被视为一个字符。 我怎么解决? 感谢。

1 个答案:

答案 0 :(得分:1)

eval(parse(...))更安全:

x <- 1:10

message("Select a vector of y values")  
nwd <- readLines(n = 1)
#input x
mean(get(nwd))
#[1] 5.5