[R] problem deparsing argument
David Winsemius
dwinsemius at comcast.net
Fri Aug 19 01:19:49 CEST 2011
On Aug 18, 2011, at 5:11 PM, Ernest Adrogué wrote:
> 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?
> bar <- function(x) class(substitute(foo(x)))
> bar(a)
[1] "call
So...
> bar <- function(x) substitute(foo(x))[[2]]
> bar(a)
a
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list