[R] getting the name of variables passed to a function

Horace Tso Horace.Tso at pgn.com
Fri Jul 27 18:52:06 CEST 2007


Folks,

I've entered into an R programming territory I'm not very familiar with, thus this probably very elementary question concerning the mechanic of a function call.

I want to know from within a function the name of the variables I pass down. The function makes use of the "..." to allow for multiple unknown arguments,

myfun = function(...) { do something }

In the body I put,

{    
nm <- names(list(...))
nm
}

When the function is called with two vectors x, and y

myfun(x, y)

It returns NULL. However, when the call made is,

>myfun(x=x, y=y)

The result is
[1] "x" "y"

Question : how do i get the names of the unknown variables without explicitly saying x=x...

Thanks in advance.

Horace



More information about the R-help mailing list