ID EN
System & OS

system2

R Base 3.6.2

system2 invokes the OS command specified by command.

Syntax

R
system2(command, args = character(),
        stdout = "", stderr = "", stdin = "", input = NULL,
        env = character(), wait = TRUE,
        minimized = FALSE, invisible = TRUE, timeout = 0)

Arguments

Parameter Description
command the system command to be invoked, as a character string.
args a character vector of arguments to command.
stdout, stderr where output to stdout or stderr should be sent. Possible values are "", to the R console (the default), NULL or FALSE (discard output), TRUE (capture the output in a character vector) or a character string naming a file.
stdin should input be diverted? "" means the default, alternatively a character string naming a file. Ignored if input is supplied.
input if a character vector is supplied, this is copied one string per line to a temporary file, and the standard input of command is redirected to the file.
env character vector of name=value strings to set environment variables.
wait a logical (not NA) indicating whether the R interpreter should wait for the command to finish, or run it asynchronously. This will be ignored (and the interpreter will always wait) if stdout = TRUE or stderr = TRUE. When running the command asynchronously, no output will be displayed on the Rgui console in Windows (it will be dropped, instead).
timeout timeout in seconds, ignored if 0. This is a limit for the elapsed time running command in a separate process. Fractions of seconds are ignored.
minimized, invisible arguments that are accepted on Windows but ignored on this platform, with a warning.
minimized logical (not NA), indicates whether the command window should be displayed initially as a minimized window.
invisible logical (not NA), indicates whether the command window should be visible on the screen.

Return Value

If stdout = TRUE or stderr = TRUE, a character vector giving the output of the command, one line per character string. (Output lines of more than 8095 bytes will be split.) If the command could not be run an R error is generated. If command runs but gives a non-zero exit status this will be reported with a warning and in the attribute "status" of the result: an attribute "errmsg" may also be available. In other cases, the return value is an error code (0 for success), given the invisible attribu

Details

Unlike system, command is always quoted by shQuote, so it must be a single command without arguments. For details of how command is found see system. On Windows, env is only supported for commands such as R and make which accept environment variables on their command line. Some Unix commands (such as some implementations of ls) change their output if they consider it to be piped or redirected: stdout = TRUE uses a pipe whereas stdout = "some_file_name" uses redirection. Because of the way it is implemented, on a Unix-alike stderr = TRUE implies stdout = TRUE: a warning is given if this is not what was specified. When timeout is non-zero, the command is terminated after the given number of seconds. The termination works for typical commands, but is not guaranteed: it is possible to write a

See Also

system. shell and shell.exec.