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

2011-11-21 Thread Jonathan Greenberg
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))

Thanks!

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
http://www.geog.illinois.edu/people/JonathanGreenberg.html

[[alternative HTML version deleted]]

__
R-help@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.


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

2011-11-21 Thread Søren Højsgaard
You can do something like this:

test - function(x,...){
 print(x)
 args = list(...)
 if('y' %in% names(args))print(args$y)
 if('z' %in% names(args))print(args$z) 
}

Regards
Søren


Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne 
af Jonathan Greenberg [j...@illinois.edu]
Sendt: 21. november 2011 23:18
Til: r-help
Emne: [R] How do I query ... in a function call?

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))

Thanks!

--j

--
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
http://www.geog.illinois.edu/people/JonathanGreenberg.html

[[alternative HTML version deleted]]

__
R-help@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.
__
R-help@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.


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

2011-11-21 Thread Steve Lianoglou
Hi Jonathan,

On Mon, Nov 21, 2011 at 5:18 PM, Jonathan Greenberg j...@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

__
R-help@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.


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

2011-11-21 Thread Mark Leeds
Hi: You can make a list out of the ... by doing below.

myfunction = function(...)
{
params - list(...)
print(params)
print(str(params))
}

On Mon, Nov 21, 2011 at 5:18 PM, Jonathan Greenberg j...@illinois.eduwrote:

 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))

 Thanks!

 --j

 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Department of Geography
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 415-763-5476
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
 http://www.geog.illinois.edu/people/JonathanGreenberg.html

[[alternative HTML version deleted]]

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.