[R] dots and substitute
Simon Anders
sanders at fs.tum.de
Sun Apr 6 20:14:33 CEST 2008
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
More information about the R-help
mailing list