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 關注
- 596 瀏覽
添加回答
舉報
