run_auto_mount: Run a containerised command with automatic mounting of files

View source: R/run_auto_mount.R

run_auto_mountR Documentation

Run a containerised command with automatic mounting of files

Description

Similar to run(), but automatically mounts files (and directories) so the user doesn't have to keep track of volumes.

Usage

run_auto_mount(
  container_id,
  command,
  args = NULL,
  wd = NULL,
  wd_in_container = NULL,
  environment_variables = NULL,
  debug = FALSE,
  verbose = FALSE,
  stdout = "|",
  stderr = "|"
)

Arguments

container_id

The name of the container, usually the repository name on dockerhub.

command

Character scalar, the command to run. If you are running .bat or .cmd files on Windows, make sure you read the 'Batch files' section in the process manual page.

args

Character vector, arguments to the command. Any files or directories that should be mounted must be named "file" (see example).

wd

Local working directory to run command. If specified, the working directory will be mounted to the docker container.

wd_in_container

Working directory to run command in the container. Defaults to the working directory mounted to the container (wd).

environment_variables

A character vector of environment variables. Format: c("ENVVAR=VALUE").

debug

If TRUE, a command will be printed that the user can execute to enter the container.

verbose

Whether or not to print output

stdout

What to do with standard output of the command. Default ("|") means to include it as an item in the results list. If it is the empty string (""), then the child process inherits the standard output stream of the R process. If it is a string other than "|" and "", then it is taken as a file name and the output is redirected to this file.

stderr

What to do with standard error of the command. Default ("|") means to include it as an item in the results list. If it is the empty string (""), then the child process inherits the standard error stream of the R process. If it is a string other than "|" and "", then it is taken as a file name and the standard error is redirected to this file.

Details

The main difference to run() is that the use of names for the args; any file (or directory) that should be mounted inside the container must be named file. The other elements (arguments) don't need to be named. Note that it is fine to have multiple elements with the same name (file).

This should generally work as long as the command accepts absolute paths for file input. If that is not the case, use run() instead and specify paths and mounting manually.

Value

List, formatted as output from processx::run()

Examples

if (test_docker_installation()) {

# Count the number of lines in the DESCRIPTION and LICENSE
# files of this package
run_auto_mount(
  container_id = "alpine",
  command = "wc",
  args = c("-l",
    file = system.file("DESCRIPTION", package = "babelwhale"),
    file = system.file("LICENSE", package = "babelwhale")
  )
)

}

dynverse/babelwhale documentation built on July 31, 2023, 2:11 a.m.