Skip to contents

Asserts that a command-line interface (CLI) tool is found on the system's PATH and returns the executable's filesystem path.

Usage

assert_cli(
  cmd,
  error_msg =
    paste0("The {.strong {cmd}} executable is required but couldn't be found on ",
    "system's {.href [PATH](https://en.wikipedia.org/wiki/PATH_(variable))}."),
  force_which = FALSE
)

Arguments

cmd

System command to invoke the CLI tool. A character scalar.

error_msg

Error message to print in case cmd is not found on system's PATH. Supports cli's inline markup. A character scalar.

force_which

If set to TRUE, base::Sys.which(), which relies on the system command which, will be used instead of command -v to determine the availability of cmd on Unix-like systems. On Windows, base::Sys.which() is used in any case. command -v is generally recommended for bourne-like shells and therefore is the default on Linux, macOS and other Unixes.

Value

If the CLI tool is available on the system's PATH, its filesystem path, invisibly. Otherwise, an error is thrown.

See also

Other system interaction functions: path_script(), test_cli()

Other functions extending the checkmate package: assert_class_any(), assert_df_or_tibble(), assert_inf_count(), assert_mime_type(), assert_pkg()

Examples

pal::assert_cli("Rscript")

cmd <- ifelse(xfun::is_windows(), "pandoc.exe", "pandoc")
pal::assert_cli(cmd)