Skip to content
Prev 70296 / 398506 Next

Returning from a function

Liaw, Andy wrote:
Or nothing at all, in which case the result of the last executed line 
will be returned.  If your function does plotting, the last line is 
probably one of the graphics functions, and they typically return 
invisible results.

Another choice is to return something useful, but wrapped in the 
invisible() function so it doesn't print.  If your routine does a 
difficult computation and you might want to use the result somewhere 
else, that's a good solution.  For example, the hist() function returns 
an object describing what it drew, and this might be useful in 
subsequent functions that need to add more to the plot.

Duncan Murdoch