test_cli: Check if CLI tool is available

test_cliR Documentation

Check if CLI tool is available

Description

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")

cmd <- ifelse(checkmate::test_os("windows"), "pandoc.exe", "pandoc")
pal::test_cli(cmd, get_cmd_path = TRUE)

salim-b/pal documentation built on Feb. 28, 2025, 6:51 p.m.