Skip to contents

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

Usage

test_cli(cmd, get_cmd_path = FALSE, force_which = FALSE)

Arguments

cmd

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

get_cmd_path

Whether or not to return the filesystem path to the CLI tool. If FALSE, a boolean is returned indicating if the CLI tool is found on the system or not.

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

A logical scalar if get_cmd_path = FALSE, otherwise the filesystem path to the cmd executable.

See also

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

Examples

pal::test_cli("Rscript")
#> [1] TRUE

cmd <- ifelse(xfun::is_windows(), "pandoc.exe", "pandoc")
pal::test_cli(cmd, get_cmd_path = TRUE)
#> /usr/bin/pandoc