Displaying 2 results from an estimated 2 matches for "sourcewithexit".
2006 Mar 14
1
New simpleExit() condition (Was: Re: Can example() code stop the example without generating an error?)
...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
# Compare this...
> code <- 'cat("Hi\n"); exit("Bye!");...
2007 Aug 27
0
Suggestion: Add simpleExit condition
...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() needs to be updated accordingly, i.e. replacing
source() with sourceWithExit().
6. src/scripts/check.in needs to updated so that the examples are
sourced detecting simpleExit:s.
Steps 1-4 can be added without side effects....