[R] Deparsing '...'

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Mar 2 17:59:13 CET 2006


Matthew Dowle <mdowle at concordiafunds.com> writes:

> Hi,
> 
> The following function works, but is there a neater way to write it?
> 
> f = function(x,...)
> {
>     # return a character vector of the arguments passed in after 'x'
>     gsub("
> ","",unlist(strsplit(deparse(substitute(list(...))),"[(,)]")))[-1] 
> }
> 
> > f(x,a,b,c*d)
> [1] "a"   "b"   "c*d"
> > 


> f <- function(x,...)as.character(match.call(expand.dots=FALSE)$...)
>  f(x,a,b,c*d)
[1] "a"     "b"     "c * d"

or maybe

f  <- function(x,...)
  sapply(match.call(expand.dots=FALSE)$..., deparse, backtick=TRUE)




-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list