如果我想打印的符号RI表示的对象可以使用引号():计算在R上的语言
> X <- list()
> print(quote(X))
X
>
但是,如果我具备的功能
h <- function(Y){
quote(Y)
}
然后
> h(X)
Y
>
是否有可能中的R编写一个函数使得
> h(X)
X
?
如果我想打印的符号RI表示的对象可以使用引号():计算在R上的语言
> X <- list()
> print(quote(X))
X
>
但是,如果我具备的功能
h <- function(Y){
quote(Y)
}
然后
> h(X)
Y
>
是否有可能中的R编写一个函数使得
> h(X)
X
?
> f = function(x) print(deparse(substitute(x)))
> f(asd)
[1] "asd"
>
为什么?正如你发现quote()
告诉R不要评估一个代码块(它与Y
一样)。 substitute()
行为不同;在?substitute
有一个很好的例子。
h <- function(x) match.call()[['x']]
h(X)
X
substitute
也工作没有额外的呼叫:
h <- function(x) substitute(x)
h(X)
X