[英]to manipulate input variable in the set of arguments of R function
I am trying to solve the issue of input variable manipulation in R function. 我正在尝试解决R函数中输入变量操纵的问题。 The function is as follows:
功能如下:
testFun<-function(x,y){
x+y
}
I want to run in such a way: 我想以这种方式运行:
testFun(x=1,y=5+x)
but the error is generated: 但生成错误:
Browse[1]> testFun(x=1,y=5+x)
浏览[1]> testFun(x = 1,y = 5 + x)
Error during wrapup: object 'x' not found包裹时出错:找不到对象“ x”
From the argument evaluation poin of view it is a mistake. 从论证评估的观点来看,这是一个错误。 So I need to have 'x' either a default value or outside value (details I have scanned in http://adv-r.had.co.nz/Functions.html#function-arguments ).
因此,我需要使用默认值或外部值“ x”(我在http://adv-r.had.co.nz/Functions.html#function-arguments中扫描的详细信息)。
So my question is whether it is possible to make such a manipulation in one row, without making a wrappers or outside values? 因此, 我的问题是,是否可以在没有包装或外部值的情况下,进行一行这样的操作?
It is supposed to have the output: 它应该具有输出:
run: 跑:
testFun(x=1,y=5+x)
testFun(x = 1,y = 5 + x)
output: 输出:
7
7
You can use <-
but it will create the variable in your global environment. 您可以使用
<-
但是它将在您的全局环境中创建变量。 See the following for example: 请参见以下示例:
testFun(x <- 1, y = 5 + x)
# [1] 7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.