Re: [R] Returning from a function

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 25 May 2005 - 00:45:10 EST

Liaw, Andy wrote:
> Use invisible(NULL) as the last line.

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

> 
> Andy
> 
> 

>>From: Laura Holt
>>
>>Hello again.
>>
>>I have a function that plots a series and adds some
>>interesting items to the
>>plot.
>>
>>Fair enough.
>>
>>The last statement in the function is
>>return()
>>
>>When the function is executed, NULL appears at the end, which is ok.
>>Is there any way to prevent NULL from appearing, or is that
>>just as it
>>should be, please?
>>
>>thanks again,
>>Shamefacedly,
>>Laura Holt
>>R Version 2.1.0 Windows
>>mailto: lauraholt_983@hotmail.com


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 25 01:04:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:01 EST