Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

exitCheck

Exit Error Checks


Description

exitCheck provides a mechanism to distinguish the exit status in on.exit expressions.

Usage

exitCheck()

Details

It generates a function that is used wihtin a function's body to "flag" normal exits and in its on.exit expression to check the exit status of a function. Note that it will correctly detect errors only if all normal exit are wrapped into a call to it.

Examples

# define some function
f <- function(err){

 # initialise an error checker
	success <- exitCheck()

 # do something on exit that depends on the error status
	on.exit({
		if(success()) cat("Exit with no error: do nothing\n") 
		else cat("Exit with error: cleaning up the mess ...\n") 
	})
	
 # throw an error here
	if( err ) stop('There is an error')
 
	success(1+1)
}

# without error
f(FALSE)
# with error
try( f(TRUE) )

pkgmaker

Development Utilities for R Packages

v0.32.2
GPL (>= 2)
Authors
Renaud Gaujoux [aut, cre]
Initial release
2020-10-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.