[R] deparse(substitute(foo))

Armstrong, Whit whit.armstrong at hcmny.com
Thu Jul 27 14:18:42 CEST 2006


I see that plot.default uses deparse(substitute(x)) to extract the
character name of an argument and put it on the vertical axis.

Hence:
foo <- 1:10
plot( foo )

will put the label "foo" on the vertical axis.

However, for a function that takes a "..." list as an input, I can only
extract the first argument name:

x <- 1:10
y <- 10:20

foo <- function(...) {
  print(deparse(substitute(...)))
}

foo(x,y)

returns: 

> foo(x,y) 
[1] "x"
> 

and when I try to convert the list to a local variable and then extract
names, that doesn't work either:

x <- 1:10 
y <- 10:20 
 
foo <- function(...) { 
 
    x <- list(...) 
    print(deparse(substitute(names(x)))) 
} 
 
foo(x,y) 

returns:

> foo(x,y)
[1] "names(list(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), c(10, 11, 12, 13, "
[2] "14, 15, 16, 17, 18, 19, 20)))"                                  
> 


Can someone suggest a way to extract the variable names when they are
passed as a list via "..." ?

Thanks,
Whit




This e-mail message is intended only for the named recipient(s) above. It may contain confidential information. If you are not the intended recipient you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and delete the message and any attachment(s) from your system. Thank you.



More information about the R-help mailing list