[R] Using names in function with ellipsis (non standard evaluation?)

Duncan Murdoch murdoch.duncan at gmail.com
Thu May 28 20:03:57 CEST 2015


On 28/05/2015 1:40 PM, Luca Cerone wrote:
> Hi everybody,
>
> this is probably a silly question, but I can't find a way to recognize
> the names that are passed
> to variables in ellipsis.
>
> For example, say I have a "core" function that receives some extra
> parameters through ...
> e.g.
>
> f <- function(...) {
>     params <- c(...)
>     #dothehardworkhere using "names(params)"
> }

The usual method is to use list(...) which retains the names, not c(...).
>
> and then I want to create a function g where some of the parameters
> are set like:
>
> g <- function(x,y) f(x,y)
>
> I figure I probably have to use to substitute in f, but it is not
> clear to me how.
>
> Definitely what I need to achieve is that when I call:
>
> g(1,2) then in f params is the vector c(x=1,y=2);
> similarly I want to be able to call g(y=2, x=1)
> and have params = c(x=1,y=2) in f.
>
> Can you please help me understanding how to do this?

Can't you just call g(...)?  I don't understand what the problem is.

Duncan Murdoch
>
> Thanks a lot for your help!
>
> Cheers,
> Luca
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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