Macro for constructing boolean check for valid path

cmd_install_is_valid(path_search, util = NULL)

Arguments

path_search

function output of cmd_path_search() NOTE: When passing the function, do not pass as: fun(), but fun to avoid evaluation.

util

value to pass to util argument of path_search, allows building individual functions for each util (if passing one of each), or for simultaneously checking all utils if setting util = TRUE. Will cause error if util = TRUE but no utils are defined. NOTE: There is no error checking for whether util is set correctly during the build process, so ensure correct spelling, etc. to avoid cryptic failures.

Value

a function returning TRUE or FALSE if a valid install is detected. With arguments: path (a path to install location), util an optional character(1) to

Examples

if (.Platform$OS.type == "unix") { search <- cmd_path_search(option_name = "bin_path", default_path = "/bin/") valid_install <- cmd_install_is_valid(search) # Returns TRUE if "/bin/" exists valid_install() # Returns FALSE if "bad/path/" doesn't exist valid_install("bad/path/") # Also works with options search_option_only <- cmd_path_search(option_name = "bin_path") valid_install2 <- cmd_install_is_valid(search_option_only) options(bin_path = "/bin/") valid_install2() # Setting util = TRUE will check that all utils are also installed search_with_utils <- cmd_path_search(default_path = "/bin", utils = c("ls", "pwd")) valid_install_all <- cmd_install_is_valid(search_with_utils, util = TRUE) valid_install_all() }
#> [1] TRUE