Skip to content
Prev 248378 / 398502 Next

return object from loop inside a function

Nicolas -
    Along with returning a value, the return function passes
control back to the caller of the function.  So any statement
after a return statement will just be ignored.
    In R the way this is handled is by returning a list.  Change

return(pop)
return(grid.dens)

to

return(list(pop=pop,grid.dens))

and you can access the two parts like this:

result = UUU(pop,grid.dens)

result$pop        # updated pop
result$grid.dens  # updated grid.dens

Hope this helps.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu
On Tue, 25 Jan 2011, Nicolas Gutierrez wrote: