Get an optional function without triggering a CRAN warning
Source:R/utils-internal.R
dot-optional_fn.Rd
You want to use a function if it is installed but don't want it to be installed as part of your package and you don't want to reference it as part of the Imports or Suggests fields in a package DESCRIPTION.
Usage
.optional_fn(
pkg,
name,
alt = function(...) {
stop("function `", pkg, "::", name, "(...)` not available")
}
)
Examples
fn = .optional_fn("openssl", "md5", digest::digest)
as.character(fn(as.raw(c(1,2,3))))
#> [1] "5289df737df57326fcdd22597afb1fac"