I would like to have the following generic function, which
- checks for thew allowedFormats (This works),
- than executes the generic function base on the type of argument x (works)
- evaluates the statements after the call of
UseMethod()
(does not work - as expected)
Now it states in the help for UseMethod
Any statements after the call to UseMethod will not be evaluated as UseMethod does not return.
So this is not surprising. But is there a way that I can achieve this, apart from defining an additional function validate_after()
which calls validate()
followed by cat(“Validation completed”)
?
validate <- function (
x,
allowedFormats
) {
# Check arguments ---------------------------------------------------------
allowedFormats <- c("none", "html", "pdf", "word", "all")
if (!(report %in% allowedFormats)) {
stop("'report' has to be one of the following values: ", allowedFormats)
}
UseMethod("validate", x)
cat(“Validation completed”)
}