maybe | R Documentation |
Wrapping a function in maybe
will modify it to return a maybe value. If
the function would normally return an error or warning the modified function
will return a 'Nothing' value, otherwise it will return a 'Just' value.
If a predicate function is provided with the parameter ensure
, if the
predicate returns TRUE
when evaluated on the return value of the function,
then a 'Just' value will be returned by the modified function, otherwise
it will return a 'Nothing' value.
maybe(.f, ensure = function(a) TRUE, allow_warning = FALSE)
.f |
A function to modify |
ensure |
A predicate function |
allow_warning |
Whether warnings should result in 'Nothing' values |
A function which returns maybe values
maybe(mean)(1:10)
maybe(mean, allow_warning = TRUE)("hello")
maybe(sqrt)("hello")
maybe(sqrt, ensure = not_infinite)(-1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.