This may be an FAQ, but a (perfunctory) search failed to turn it up.
Suppose I have a function foo(...){<something>} and I want to obtain,
inside foo, the names of items comprising the ``...''. E.g. if I
call
foo(melvin,clyde,irving)
I want to be able to loop through the ``...'' and successively obtain
the text strings "melvin", "clyde", and "irving".
Is there any way to do this?
I know that if I had a function foo(x,y,z){<something>}, and I called
foo(melvin,clyde,irving), I could get the text strings I want by
means of
deparse(substitute(x)) # Giving "melvin".
deparse(substitute(y)) # Giving "clyde".
deparse(substitute(z)) # Giving "irving".
but if foo() is to take an arbitrary number of arguments then this
sort of syntax is not available.
cheers,
Rolf Turner
rolf at math.unb.ca
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 11 Apr 2002, Rolf Turner wrote:> This may be an FAQ, but a (perfunctory) search failed to turn it up. > > Suppose I have a function foo(...){<something>} and I want to obtain, > inside foo, the names of items comprising the ``...''. E.g. if I > call > > foo(melvin,clyde,irving) > > I want to be able to loop through the ``...'' and successively obtain > the text strings "melvin", "clyde", and "irving". > > Is there any way to do this? >R> f function(...){ substitute(list(...)) } R> f(melvin,clyde,irving) list(melvin, clyde, irving) If you want text strings you will have to convert them with eg as.character, or supply text strings as the arguments R> f("melvin","clyde","irving") list("melvin", "clyde", "irving") -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
foo <- function(...) as.character(match.call(expand.dots = FALSE)$"...") should give you the names a a character vector. --- Rolf Turner <rolf at math.unb.ca> wrote:> This may be an FAQ, but a (perfunctory) search failed to turn it up. > > Suppose I have a function foo(...){<something>} and I want to obtain, > inside foo, the names of items comprising the ``...''. E.g. if I > call > > foo(melvin,clyde,irving) > > I want to be able to loop through the ``...'' and successively obtain > the text strings "melvin", "clyde", and "irving". > > Is there any way to do this? > > I know that if I had a function foo(x,y,z){<something>}, and I called > foo(melvin,clyde,irving), I could get the text strings I want by > means of > > deparse(substitute(x)) # Giving "melvin". > deparse(substitute(y)) # Giving "clyde". > deparse(substitute(z)) # Giving "irving". > > but if foo() is to take an arbitrary number of arguments then this > sort of syntax is not available. > > cheers, > > Rolf Turner > rolf at math.unb.ca >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.___________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._