shell: Invoke a command in the system command-line shell

View source: R/shell.R

shellR Documentation

Invoke a command in the system command-line shell

Description

Invoke a command in the system command-line shell

Usage

shell(
  command,
  args = character(),
  env = NULL,
  wd = getwd(),
  print = TRUE,
  stderrFile = NULL,
  stdoutFile = NULL,
  stderrToStdout = FALSE,
  returnStdout = FALSE
)

Arguments

command

character(1). Name of program to run.

args

character. Arguments passed to command.

env

character or NULL. Environment variables of the child process. If NULL, the parent environment is inherited. To append new environment variables to the ones set in the current process, specify "current" in env, without a name, and the appended ones with names. The appended ones can overwrite the current ones.

wd

character(1). Working directory path inside process.

print

logical(1). Whether to print (echo) the commands to the console.

stdoutFile, stderrFile

character(1) or NULL. File path to log stdout and/or stderr. Disabled when set NULL.

stderrToStdout

logical(1). Whether to redirect standard error (stderr) to standard output (stdout). Similar to ⁠2>&1⁠ in POSIX or ⁠&>⁠ in Bash.

returnStdout

logical(1). Whether to return stdout as a character vector, split by "\n".

Value

Invisible list. Contains named elements: "status", "stdout", "stderr", "timeout".

Note

Updated 2023-11-04.

See Also

  • processx::run().

  • base::system2(), our previously used legacy approach.

Examples

x <- shell(
    command = "printf",
    args = c("%s\n", "hello", "world"),
    print = TRUE
)
print(x)

acidgenomics/acidbase documentation built on Jan. 26, 2024, 4:26 p.m.