[R-SIG-Mac] Help request w/ function argument names

Don MacQueen macq at llnl.gov
Thu May 15 05:38:14 CEST 2008


Carl,

When I try Vincent's function in my R GUI, it works, and the argument 
names are available as strings:


>  f <- function (...)
+ {
+ l <- list(...) # Put the arguments in a (named) list
+ for (i in seq(along=l))
+ {
+ cat("Argument name:", names(l)[i], "Value:", l[[i]], "
+ \n")
+ }
+ }
>
>  f(x=3,y=2)
Argument name: x Value: 3

Argument name: y Value: 2


However, you do have to supply values along with the arguments:

>  x<-4
>  f(x,y=2)
Argument name:  Value: 4

Argument name: y Value: 2


By the way, this is not a Mac issue. It has to do with environments 
and how arguments are passed.

list(...) has names only for those arguments that are supplied as 
named arguments, and in
      > f(x,y=2)
the second argument is named but the first is not. Well, that is, I 
think I'm using proper terminology.


-Don


At 6:14 PM -0400 5/14/08, Carl Witthoft wrote:
>Hi,
>I've been trying to figure out if there's a way to return the actual 
>names of the arguments passed to a function which uses ellipsis.
>
>There's an example in Vincent Zoonekynd's <zoonek at math.jussieu.fr> 
>manual that looks like this:
>
>f <- function (...)
>{
>l <- list(...) # Put the arguments in a (named) list
>for (i in seq(along=l))
>{
>cat("Argument name:", names(l)[i], "Value:", l[[i]], "
>\n")
>}
>}
>
>
>I don't know exactly what he thought would happen (or what happens 
>from the command line?) but from the Mac Aqua GUI, names(l) 
>evaluates to NULL, or possibly the 'names' attribute of the first 
>element of the first argument passed to the function, if such 
>exists.   And in fact 'l'  contains the values of all elements of 
>the arguments to f.
>
>So, is there any way to have the function 'f'  "know" what the names 
>are of the arguments passed to it?  That is, if I type
>
>
>>  f(foo,bar)
>
>I would like to be able to have the strings 'foo' and 'bar' available somehow.
>
>Any advice or comments greatly appreciated.
>
>Carl
>
>_______________________________________________
>R-SIG-Mac mailing list
>R-SIG-Mac at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/r-sig-mac


-- 
---------------------------------
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
macq at llnl.gov



More information about the R-SIG-Mac mailing list