[R] problem deparsing argument

Ernest Adrogué nfdisco at gmail.com
Thu Aug 18 23:11:42 CEST 2011


Hi,

I don't know much about R's deparsing "magic", I simply use the
deparse(substitute(arg)) trick to get the names of the variables
passed as arguments to the function in order to set labels, etc.

The problem is that this doesn't work with nested functions. For
example, 

> foo <- function(x) print(deparse(substitute(x)))
> a=1
> foo(a)
[1] "a"

This is OK. However,

> bar <- function(x) foo(x)
> bar(a)
[1] "x"

this is not what I want. I wanted bar(a) to print "a" not "x". Is it
possible to do this?

Thanks in advance.

-- 
Ernest



More information about the R-help mailing list