Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make R exit with non-zero status code

Tags:

r

exit

I am looking for the R equivalent of linux/POSIX exit(n) which will halt the process with exit code n, signaling to a parent process that an error had occurred. Does R have such a facility?

like image 261
Setjmp Avatar asked Oct 06 '11 22:10

Setjmp


People also ask

What is a non-zero exit code?

A non-zero exit status indicates failure. This seemingly counter-intuitive scheme is used so there is one well-defined way to indicate success and a variety of ways to indicate various failure modes. When a command terminates on a fatal signal whose number is N , Bash uses the value 128+ N as the exit status.

How do you exit an R code?

To quit R you can either use the RStudio > Quit pull-down menu command or execute ⌘ + Q (OS X) or ctrl + Q (PC).


1 Answers

It's an argument to quit(). See ?quit.

Arguments:

status: the (numerical) error status to be returned to the operating         system, where relevant.  Conventionally ‘0’ indicates         successful completion. 

Details:

 Some error statuses are used by R itself.  The default error  handler for non-interactive use effectively calls ‘q("no", 1,  FALSE)’ and returns error code 1.  Error status 2 is used for R  ‘suicide’, that is a catastrophic failure, and other small numbers  are used by specific ports for initialization failures.  It is  recommended that users choose statuses of 10 or more. 
like image 192
Joshua Ulrich Avatar answered Sep 20 '22 08:09

Joshua Ulrich