Description Usage Arguments Details Value Note Author(s) References Examples
The function raincheck
creates a function that will manipulate the
environment where it is called. The scold
function writes error
messages that appear to come from that same environment. Both functions
make it easier to separate code that reformats arguments from the main
code of a function.
1 2 |
expr |
R code that will operate on the environment of the
function that calls the function returned by |
text |
An error message to display to the user. |
action |
The type of error message. |
... |
Additional arguments to pass to the condition generated in
|
Fill in after the package evolves a little.
raincheck
returns a function that manipulates the environment
where it is called. See the examples below.
Some code in the scold
function is based on/borrowed from
Wickham's (2013) Advanced R programming, see
http://adv-r.had.co.nz/Exceptions-Debugging.html#condition-handling.
Gray Calhoun gcalhoun@iastate.edu
Wickham, Hadley (2013) Advanced R Programming. Chapman and Hall. http://adv-r.had.co.nz/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | f1 <- function(x) {
FormatArguments_f1() # Yikes; *only* side effects
## Important, logical stuff goes here
x[10,10]
}
FormatArguments_f1 <- raincheck({
if (!is.matrix(x)) {
scold("'x' really should have been a matrix.")
x <- as.matrix(x)
}
if (any(x == 30)) {
scold("Cool, I love the number thirty.\n", "message")
}
if (nrow(x) < 10 || ncol(x) < 10) {
scold("'x' must have at least 10 rows and 10 columns.", "stop")
}
})
f1(matrix(30, 11, 11))
f1(matrix(31, 11, 11))
## Not run: f1(30)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.