Description Usage Arguments Details Value Examples
Maybe apply function to value
1 | maybe(f, x, y = x)
|
f |
Function to be applied to ‘x’ |
x |
Object to which ‘f’ should be applied |
y |
Alternative value to return if applying ‘f’ to ‘x’ leads to an error or a warning |
Errors or warnings caused by evaluating ‘x’ will not be caught.
The purpose of maybe
is only to catch errors and warning
caused by evaluating ‘f(x)’.
‘f(x)’ unless that results in an error or a warning, otherwise ‘y’.
1 2 3 4 5 6 7 | x <- "12"
y <- "foo"
maybe(as.integer, x)
maybe(as.integer, y)
maybe(as.integer, y, 0L)
tryCatch(maybe(as.integer, stop(), 0L),
error = function(e) pr("Evaluating `x' caused an error."))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.