3 回答
TA贡献1825条经验 获得超6个赞
eval(parse(...))
eval(parse(..))
get
[[
$
[[
eval(parse(..))
TA贡献1836条经验 获得超5个赞
eval
eval(parse(
std <- function(){ mean(1to10)}
ep <- function(){ eval(parse(text = "mean(1to10)"))}
system.time(for(i in seq_len(1e4)) mean(1:10)) user system elapsed 0.08 0.00 0.07
system.time(for(i in seq_len(1e4)) eval(parse(text = "mean(1:10)"))) user system elapsed 1.54 0.14 1.69
TA贡献2003条经验 获得超2个赞
require(gtools)# both action_to_take & predicate will be subbed with codeF <- defmacro(predicate, action_to_take, expr = if(predicate) action_to_take)F(1 != 1, action_to_take = print('arithmetic doesnt work!'))F(pi > 3, action_to_take = return('good!'))[1] 'good!'# the raw code for Fprint(F)function (predicate = stop("predicate not supplied"), action_to_take = stop("action_to_take not supplied")) { tmp <- substitute(if (predicate) action_to_take) eval(tmp, parent.frame())}<environment: 0x05ad5d3c>
- 3 回答
- 0 关注
- 550 浏览
添加回答
举报