Re: [R] exit function in R?

From: Rolf Turner <r.turner_at_auckland.ac.nz>
Date: Tue, 03 Jun 2008 09:15:23 +1200

On 3/06/2008, at 1:18 AM, Federico Abascal wrote:

> Hi,
> This is likely an stupid question, but I cannot find the solution.
> I am searching for an "exit" function, to end the execution of an R
> script if some condition is not filled.
> Any clue?

Others have suggested using stop(). It might be the case that the condition not being fulfilled is not actually a sign of an error, but simply of a different, perhaps ``marginal'' situation in which a different sort of action or calculation is required. In which case what you want is return().

Trivial e.g.:

foo <- function(x) {

	if(any(x<=0)) return(42)
	y <- sum(log(x))
	y

}

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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. Received on Mon 02 Jun 2008 - 22:12:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jun 2008 - 04:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive