[R] pass objects into "..." (dot dot dot)

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue May 15 18:53:32 CEST 2012


Hi,

On Tue, May 15, 2012 at 12:46 PM, Ben quant <ccquant at gmail.com> wrote:
> Hello,
>
> Thanks in advance for any help!
>
> How do I pass an unknown number of objects into the "..." (dot dot dot)
> parameter? Put another way, is there some standard way to pass multiple
> objects into "..." to "fool" the function into thinking the objects are
> passed in separately/explicitly with common separation (like "x,y,z" when
> x, y and z are objects to be passed into "...")?

Calling `list(...)` will return a list as long as there are elements
caught in `...`

Does this help?

R> howMany <- function(...) {
  args <- list(...)
  cat("There are", length(args), "items passed in here\n")
}

R> howMany(1, 2, 3, 4)
There are 4 items passed in here

R> howMany(10, list(1:10))
There are 2 items passed in here

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list