Displaying 2 results from an estimated 2 matches for "evalwithexit".
2006 Mar 14
1
New simpleExit() condition (Was: Re: Can example() code stop the example without generating an error?)
...signals via
tryCatch(..., simpleExit=function(se) {...}). Here is a complete
example:
simpleExit <- function(...) {
cond <- simpleCondition(...)
class(cond) <- c("simpleExit", class(cond))
cond
}
exit <- function(...) {
invisible(signalCondition(simpleExit(...)))
}
evalWithExit <- function(...) {
tryCatch(..., simpleExit=function(cond) cond)
}
sourceWithExit <- function(...) {
evalWithExit(source(...))
}
Examples:
> evalWithExit({cat("Hi\n");exit("Bye!");cat("there\n")}); cat("bye\n")
Hi
<simpleExit: Bye!>
bye...
2007 Aug 27
0
Suggestion: Add simpleExit condition
...", class(cond)) cond
}
2. Setup a method to generate such a condition similar to warning() and stop():
exit <- function(...) {
invisible(signalCondition(simpleExit(...))) }
}
3. That is the basic framework. We can then use tryCatch() to catch
and return upon a simpleExit as follows:
evalWithExit <- function(...) {
tryCatch(..., simpleExit=function(cond) cond) }
}
Then it is matter of flavor if one wants to update source() with an
argument 'allowExits=FALSE' or have a standalone function:
sourceWithExit <- function(...) {
evalWithExit(source(...))
}
5. The code example(...