Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
r替换为列表和评估_R_List_Lazy Evaluation_Substitution - Fatal编程技术网

r替换为列表和评估

r替换为列表和评估,r,list,lazy-evaluation,substitution,R,List,Lazy Evaluation,Substitution,如果我举个例子 match_caller <- function(x) 1L crazy_function <- function(x) substitute(match_caller(x),list(x=x)) crazy_function2 <- function(x) substitute(match_caller(x)) a <- 10L crazy_function(a^2) #> match_caller(100) crazy_function2(a^

如果我举个例子

match_caller <- function(x) 1L
crazy_function <- function(x) substitute(match_caller(x),list(x=x))
crazy_function2 <- function(x) substitute(match_caller(x))

a <- 10L
crazy_function(a^2)
#> match_caller(100)
crazy_function2(a^2)
#> match_caller(a^2)

match\u caller关于/lazy评估,我认为已经有了一些很好的答案。我只想引用(可以追溯到S语言时代):

论据 expr:任何语法上有效的R表达式
环境:环境或列表对象。默认为当前评估环境

所以,是的,你可以使用一个列表,但这不是原力的作用

这是您调用它的方式,如中所示,其中再次显示了如何替换值中的表达式:


substituteExpr我想说你不需要
force
。正如您从
?substitute
中的示例中所看到的,这正是您应该如何使用
substitute
。另外,作为记录,如果
match_caller@Edo Hi,是的,谢谢你的评论,你会得到完全相同的结果。我放置match call是因为我想这样做以捕获经过评估的调用。但我会把你的注意放在我的简单例子上。我认为,
?替换项
是否评估列表参数并不清楚。感谢您的回复。我的问题不是关于如何使用substitute,而是关于env arg中调用的列表。我想知道它是否经过系统评估,但我在你展示的帖子中找不到答案。对不起,如果你不太清楚的话。
substituteExpr <- function(expr, env) {
  do.call(substitute, list(expr=expr[[1]], env=env))
}
substituteExpr(a^2, list(x=2)) # 100