arglist_parse: Normalise arguments for docker container

Description Usage Arguments Details Value Examples

View source: R/args.R

Description

Utility function for parsing the arguments provided by a user. Drop any specified key:value pairs with keyvals_to_drop or drop any specific values vals_to_drop. With normalise_paths as TRUE, all filepaths in the arglist will be converted to basenames.

Usage

1
2
3
4
5
6
arglist_parse(
  arglist,
  keyvals_to_drop = NULL,
  vals_to_drop = NULL,
  normalise_paths = TRUE
)

Arguments

arglist

Arguments as character vector

keyvals_to_drop

Argument keys to drop, e.g. -wd.

vals_to_drop

Specific values to drop, e.g. –verbose.

normalise_paths

Reduce paths to basenames? Default, TRUE.

Details

It is important the file paths are normalised, because they will not be available to the Docker container. The only files available will be those that have been transferred to the container as determined through the outsider_init. These files will be located in the same directory as where the function is called and require no absolute file path.

Value

Character vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(outsider.base)
wd <- file.path(tempdir(), 'results')
dir.create(wd)
arglist <- c('-a', 10, '-b', 'model2', '-wd', wd, '--unwanted')
# drop unwanted key:value pairs
(arglist_parse(arglist = arglist, keyvals_to_drop = '-wd',
               normalise_paths = FALSE))
# drop unwanted argument values
(arglist_parse(arglist = arglist, vals_to_drop = '--unwanted',
               normalise_paths = FALSE))
# make paths relative, necessary for Docker:
#   paths must be relative to the working directory in the container
(arglist_parse(arglist = arglist, normalise_paths = TRUE))


# clean-up
unlink(wd, recursive = TRUE)

outsider.base documentation built on April 19, 2021, 1:06 a.m.