[R] Recovering object names when using the ... argument in a fn XXXX

William Dunlap wdunlap at tibco.com
Fri Oct 18 19:27:48 CEST 2013


> I am using the ... argument to parmeterize a user define fn to accept
> multiple input objects. I subsquently save all these data as a list.
> Question: what is the best way to recover or extract the original object
> names that were fed to the fn?

The following function, ellipsisInfo, returns character strings representing the
actual arguments to the function.  If the function was called with tags on the
arguments, as in ellipsisInfo(tag=argument), it makes those tags the names
on the returned character  vector.  It does not evaluate the ... arguments, so
you don't run into problems with evaluating arguments too soon or evaluating
ones that should not be evaluated most of the time. 

ellipsisInfo <- function(...) {
    # get the unevaluated expressions given as arguments
    unevaluatedArgs <- substitute(...())
    # convert those expressions to text (truncate to single line)
    unevaluatedArgsAsText <- vapply(unevaluatedArgs, function(a)deparse(a)[1], "")
    unevaluatedArgsAsText
}

E.g.,

> i <- ellipsisInfo(x, log(10), e=exp(1), onProblem=stop("there was a problem"))
> i
                                
                            "x" 
                                
                      "log(10)" 
                              e 
                       "exp(1)" 
                      onProblem 
"stop(\"there was a problem\")" 
> ifelse(names(i)=="", i, names(i)) # use tag if supplied, otherwise argument itself
[1] "x"         "log(10)"   "e"        
[4] "onProblem"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Dan Abner
> Sent: Friday, October 18, 2013 9:06 AM
> To: r-help at r-project.org
> Subject: [R] Recovering object names when using the ... argument in a fn XXXX
> 
> Hi all,
> 
> I am using the ... argument to parmeterize a user define fn to accept
> multiple input objects. I subsquently save all these data as a list.
> Question: what is the best way to recover or extract the original object
> names that were fed to the fn?
> 
> Thanks,
> 
> Dan
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list