[R] function design: multiple imput names

Joshua Wiley jwiley.psych at gmail.com
Sun Jul 17 23:51:59 CEST 2011


Hi John,

Look at ?match.call you will need to make sure that expand.dots =
TRUE, but I think it does what you want.  The names you want might be:

names(my_list) <- as.character(match.call(expand.dots = TRUE))[-1L]

I will point out that I am not sure you will get the desired results
with your function as it is written.  I think you might want:


f <- function(...) {
  d <- list(...)
  lapply(d, function(x){x})
}

instead.

Hope this helps,

Josh

On Sun, Jul 17, 2011 at 10:59 AM, John Lande <john.lande77 at gmail.com> wrote:
> dear all,
>
> a simple question, I need to write a function in which I retrive an
> undetermined number of vector in the function.
>
> I solved the problem thanks to this link
>
> http://stackoverflow.com/questions/2540232/how-to-allow-multiple-inputs-from-user-using-r
>
> so my function will look alike this
>
> my_fun <- function(...){
>   my_list <- lapply(..., function(x){x})
> }
>
> I need just one more suggestion.
>
> how can give to each element of the list the name of the single variables I
> used as imput of "my_fun"??
>
> I hope I was clear in what I want to do
>
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list