[R] How do I query "..." in a function call?

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon Nov 21 23:28:57 CET 2011


Hi Jonathan,

On Mon, Nov 21, 2011 at 5:18 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
> This is probably a very noobish question, but if I want to create a
> function that allows an undetermined number of, say, numeric vectors to be
> fed to it, I would use:
>
> myfunction = function(...)
> {
> # Do something
>
> }
>
> Right?  If so, how do I a) count the number of vectors "fed" to the
> function, and b) how do I treat those vectors as variables, e.g. for the
> call:
>
> myfunction(c(1:10),c(2:11),c(3:13))

`args <- list(...)` will create a list out of the "things" passed
through in `...`

For example:

myfunction <- function(...) {
  args <- list(...)
  length(args) ## this is how many things were passed in
  names(args) ## these are the variable names used
  ## etc.
}

HTH,
-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