Given name
, the absolute or relative path to an R or shell script,
with or without the file extension, return the path to the shell script.
Verify the name
is legitimate in terms of file existence or existence
of the appropriate parent directory (if name
is an absolute path).
parse_file_or_name(name, should_exist, r_ok)
A character(1)
vector giving either the name or path
(relative or absolute) to the shell or R script to create
A logical(1)
vector. If TRUE, the specified script
must already exist; if FALSE, it must not exist
A logical(1)
vector. If TRUE, name
may end in '.R'
A character(1)
giving the absolute or relative path to the
shell script
acceptable_names <- c(
# Absolute paths/ names may be used
file.path(getwd(), "my_script.sh"),
file.path(getwd(), "my_script.R"),
file.path(getwd(), "my_script"),
# Relative paths/ names are also acceptable
"my_script.sh",
"my_script.R",
"my_script"
)
returned_scripts <- sapply(
acceptable_names, slurmjobs:::parse_file_or_name,
should_exist = FALSE, r_ok = TRUE
)
print(returned_scripts)
#> /__w/slurmjobs/slurmjobs/docs/reference/my_script.sh
#> "/__w/slurmjobs/slurmjobs/docs/reference/my_script.sh"
#> /__w/slurmjobs/slurmjobs/docs/reference/my_script.R
#> "/__w/slurmjobs/slurmjobs/docs/reference/my_script.sh"
#> /__w/slurmjobs/slurmjobs/docs/reference/my_script
#> "/__w/slurmjobs/slurmjobs/docs/reference/my_script.sh"
#> my_script.sh
#> "my_script.sh"
#> my_script.R
#> "my_script.sh"
#> my_script
#> "my_script.sh"