Re: [R] dots and substitute

From: Simon Anders <anders_at_ebi.ac.uk>
Date: Sun, 06 Apr 2008 22:51:48 +0100

Hi Charles,

Charles C. Berry wrote:
> Try this:
>
> f2 <- function(...) sapply( substitute(list(...)), deparse )[-1]

Wow, this works. Thanks a lot!

> p.s. Why do you want this as mode "character"?

For the usual purpose of 'substitute': to label something. The use case is that I have a function that takes an unspecified number of very large integer vectors which are visualized in some way. I first tried to pass all the vectors as one list, via '.Call', but that made R duplicate the vectors, when the list argument is built. So, I now use '...' and '.External', where duplication does not happen. I would like to conveniently label the vectors by the expression with which they have been passed (as 'plot' does, too), and with your construction, I can now extract the expressions as characters and pass them to make the labels.

> Warning:
>

>> fortune(106)

>
> If the answer is parse() you should usually rethink the question.
> -- Thomas Lumley
> R-help (February 2005)

Then, I am lucky that you offered a solution with 'deparse', not 'parse'. ;-) Still, I am (pleasently) surprised that the vectors within the '...' do not get duplicated (according to 'tracemem') by this construction.

Thank you very much

   Simon



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 06 Apr 2008 - 21:54:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 06 Apr 2008 - 22:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive