[R] dots and substitute

From: Simon Anders <sanders_at_fs.tum.de>
Date: Sun, 06 Apr 2008 19:14:33 +0100


Hi,

is there an elegant way to use 'substitute' with '...' arguments?

My first try was this:

> f1 <- function(...) substitute(...)
> f1( 2+7, "foo", 3+5 )

2 + 7

As you can see, substitute acts only on the first argument. So I tried

> f2 <- function(...) substitute(list(...))
> f2( 2+7, "foo", 3+5 )

list(2 + 7, "foo", 3 + 5)

This is now all the information I want, but it is not split into the individual arguments. I would like to get a character vector, i.e. something like

   c( "2 + 7", "\"foo\"", "3 + 5" )

My third try seems to be wrong as well:

> f3 <- function(...) lapply( list(...), substitute )
> f3( 2+7, "foo", 3+5 )

Error in lapply(list(...), substitute) :

   '...' used in an incorrect context

Does anybody has a good hint for me as how to do it correctly?

Thanks

   Simon

+---

| Dr. Simon Anders, Dipl. Phys.
| European Bioinformatics Institute, Hinxton, Cambridgeshire, UK
| preferred (permanent) e-mail: sanders_at_fs.tum.de

______________________________________________
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 - 18:17:13 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 - 20:31:08 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