对不起我的英文不好得到R中的输出变量的
是否有R A的方式获得用于函数内的一个函数的返回值的名称,以同样的方式,你可以赶上名称输入变量名称为“substitute”??。我的意思是这样“outputname”功能:
myFun=function(x){
nameIN=substitute(x)
nameOUT=outputname()
out=x*2
cat("The name of the input is ", nameIN," and this is the value:\n")
print(x)
cat("The name of the output is ", nameOUT, "and this is the value:\n")
print(out)
return(out)
}
这是我的心愿:
> myINPUT=12;
> myOUTPUT=myFun(myINPUT)
The name of the input is myINPUT and this is the value:
[1] 12
The name of the output is myOUTPUT and this is the value:
[1] 24
> myOUTPUT
[1] 24
我一直在寻找一个答案,我要疯了。这似乎很简单,但我 找不到任何东西。
谢谢
这是不可能的,至少不是所谓的函数。 – gagolews
你不能这样做。接下来最好的事情是将myOUTPUT作为参数传递给myFun,并使用替代品来获取其名称。 –
你可以使用'assign'而不是'='或'<-'吗?与其命名参数的基元相反。 – Roland