View source: R/adverb-possibly.R
possibly | R Documentation |
Create a modified version of .f
that return a default value (otherwise
)
whenever an error occurs.
possibly(.f, otherwise = NULL, quiet = TRUE)
.f |
A function to modify, specified in one of the following ways:
|
otherwise |
Default value to use when an error occurs. |
quiet |
Hide errors ( |
A function that takes the same arguments as .f
, but returns
a different value, as described above.
This function is called an adverb because it modifies the effect of a function (a verb). If you'd like to include a function created an adverb in a package, be sure to read faq-adverbs-export.
Other adverbs:
auto_browse()
,
compose()
,
insistently()
,
negate()
,
partial()
,
quietly()
,
safely()
,
slowly()
# To replace errors with a default value, use possibly().
list("a", 10, 100) |>
map_dbl(possibly(log, NA_real_))
# The default, NULL, will be discarded with `list_c()`
list("a", 10, 100) |>
map(possibly(log)) |>
list_c()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.