util_ensure_suggested: Support function to stop, if an optional package is not...

View source: R/util_ensure_suggested.R

util_ensure_suggestedR Documentation

Support function to stop, if an optional package is not installed

Description

This function stops, if a package is not installed but needed for using an optional feature of dataquieR.

Usage

util_ensure_suggested(
  pkg,
  goal = ifelse(is.null(rlang::caller_call()), "work", paste("call",
    sQuote(rlang::call_name(rlang::caller_call())))),
  err = TRUE,
  and_import = c()
)

Arguments

pkg

needed package

goal

feature description for error message.

err

logical Should the function throw an error (default) or a warning?

and_import

import the listed function to the caller's environment

Value

TRUE if all packages in pkg are available, FALSE if at least one of the packages is missing.

See Also

Other robustness_functions: util_as_valid_missing_codes(), util_check_one_unique_value(), util_correct_variable_use(), util_empty(), util_ensure_character(), util_ensure_in(), util_expect_scalar(), util_fix_rstudio_bugs(), util_is_integer(), util_is_numeric_in(), util_is_valid_missing_codes(), util_match_arg(), util_observations_in_subgroups(), util_only_NAs(), util_stop_if_not(), util_warn_unordered()

Examples

## Not run:  # internal use, only
f <- function() {
  util_ensure_suggested <- get("util_ensure_suggested",
    asNamespace("dataquieR"))
  util_ensure_suggested("ggplot2", "Test",
      and_import = "(ggplot|geom_.*|aes)")
  print(ggplot(cars, aes(x = speed)) + geom_histogram())
}
f()

## End(Not run)


dataquieR documentation built on May 29, 2024, 7:18 a.m.