Skip to contents

Drop-in replacement for purrr::possibly that returns a default value when an error occurs instead of throwing the error.

Usage

s_possibly(.f, otherwise, quiet = TRUE)

Arguments

.f

A function to wrap for safe execution.

otherwise

Default return value when an error occurs.

quiet

Logical. Hide errors from console if TRUE.

Value

A function that returns the result or the default value.

Examples

safe_log <- s_possibly(log, otherwise = NA)
safe_log(10) # Returns 2.30
#> [1] 2.302585
safe_log("a") # Returns NA
#> [1] NA