[R] return of a function

David Winsemius dwinsemius at comcast.net
Fri Apr 16 18:12:37 CEST 2010


On Apr 16, 2010, at 12:02 PM, Gustave Lefou wrote:

> Dear R users,
>
> I have a function which takes as arguments big arrays, say : w, x ,  
> y and z.
>
> My function changes these arrays and I want them as result/output.
>
> I have tried to write return(w,x,y,z), and thus to replace the  
> previous w,
> x, y and z. It does not seem to work.

Right. Two misconceptions here. First, return() accepts one object,  
which could be a list of items. Second, just because you return it  
with a name that is the same as some obkect outside the function does  
not mean that the new values will be placed in the "outside object".  
In fact if you do not assign the returned value to something, it will  
be temporarily placed in .LastValue and then overwritten when the next  
evaluation operation occurs. You need to assign the result of a  
function to some object.

>
> What can I do ?

Read more about functions and do more examples with small objects to  
see the effects on test cases.

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list