如果我想打印的符號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