Make R exit with non-zero status code

RExit

R Problem Overview


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?

R Solutions


Solution 1 - R

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.

Solution 2 - R

quit(status=1)

Replace 1 by whatever exit code you need.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSetjmpView Question on Stackoverflow
Solution 1 - RJoshua UlrichView Answer on Stackoverflow
Solution 2 - RligandView Answer on Stackoverflow