If I want to print the symbol denoting an object in R I can use quote():
> X <- list()
> print(quote(X))
X
>
However, if I have the function
h <- function(Y){
quote(Y)
}
then
> h(X)
Y
>
Is it possible in R to write a function such that
> h(X)
X
?
> f = function(x) print(deparse(substitute(x)))
> f(asd)
[1] "asd"
>
Why? As you've found out quote()
tells R to not evaluate a code block (which it does with Y
). substitute()
behaves differently; there's a good example at ?substitute
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With