Skip to content
Prev 34946 / 63424 Next

Issue when calling deparse(substitute(x)) from C with "anonymous" R vectors ?

Thanks to you and Peter for the quick answer.

I should definitely have tried I R. It just seemed to me so unlikely 
that no one ever reported that anonymous vectors would fail with 
chisq.test().

Having a label that would be x or y is along the lines of something I 
was thinking of, and this not only for chisq.test(). It would be helpful 
for functions such as plot() for example.

The idea would be to replace an anonymous object by its variable name, 
unless the anonymous variable is coming from a function call.

Example:

foo <- function(x) {
   xlabel <- deparse(substitute(x))
   # do things
}

foo(y) # xlabel is 'y'

foo(log(y)) # xlabel is 'log(y)'

foo(c(1,2,3)) # xlabel is 'x'

foo(log(c(1,2,3)) # xlabel is 'x'

This would likely require looking at the parse tree for the argument, 
and have a switch such as "if any leave is an anonymous object, use the 
parameter name".



L.
Prof Brian Ripley wrote: