[R] Create a function with multiple object as an output

Jim Holtman jholtman at gmail.com
Wed Feb 10 15:27:52 CET 2010


you can return a single object, so a list is what you want. you can  
always break it apart after the return.

What is the problem you are trying to solve?

Sent from my iPhone.

On Feb 10, 2010, at 8:31, Arnaud Mosnier <a.mosnier at gmail.com> wrote:

> Dear useRs,
>
> I want to make a function that return several object (from a loop).
> I know, I can put them in a list, then the function return  the list,
> but is it possible that it returns several independent object.
> I used the assign function to create several object, it works when I
> use it outside the function, but not inside.
>
> Any suggestion ?
>
> Here is a piece of code that do something similar to my situation.
>
> testfunc <- function ( listobj, valueX) {
>        for (i in 1:length(listobj)) {
>             objtemp <- get (listobj[i])
>             objtemp <- objtemp * valueX
>             assign(paste(listobj[i], "_", valueX, sep=""), objtemp)
>        }
> return (??????????????????????)
> }
>
> ______________________________________________
> 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