Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing on the Language in R

Tags:

r

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

?

like image 651
gappy Avatar asked Mar 07 '11 22:03

gappy


1 Answers

> 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.

like image 111
Vince Avatar answered Oct 22 '22 01:10

Vince