A pipeline object represents a sequence of processes whose standard
input and output streams are connected with pipes, like a Unix pipeline
(cmd1 | cmd2 | cmd3). Data flows directly between the child processes
via kernel-level pipes — the parent R process sees only the output of the
final command (when stdout = "|").
Methods
pipeline$new(cmds, stdin, stdout, stderr, env, encoding, wd, cleanup, cleanup_tree)
$read_output(n = -1), $read_output_lines(n = -1),
$read_all_output(), $read_all_output_lines() — read from the last
process (only meaningful when stdout = "|").
$poll_io(timeout) — poll the last process's connections for I/O.
$read_error(n = -1), $read_error_lines(n = -1),
$read_all_error(), $read_all_error_lines() — read stderr of the
last process (only meaningful when stderr = "|").
$write_input(str, sep = "\n") — write to first process stdin
(only meaningful when stdin = "|").
$close_input() — close the first process stdin, signalling EOF.
$wait(timeout = -1) — wait for all processes to finish.
$kill(grace = 0.1, close_connections = TRUE) — kill all processes.
$kill_tree(grace = 0.1, close_connections = TRUE) — kill all
process trees.
$is_alive() — returns TRUE if any process is still running.
$get_exit_statuses() — list of exit codes (one per process; NULL
if still running).
$get_pids() — integer vector of process IDs.
$get_processes() — list of process objects, one per command.
$format() — string representation of the pipeline.
$print() — print the pipeline to the screen.
Methods
Method new()
Create a new pipeline.
Usage
pipeline$new(
cmds,
stdin = NULL,
stdout = "|",
stderr = NULL,
env = NULL,
encoding = "utf-8",
wd = NULL,
cleanup = TRUE,
cleanup_tree = FALSE
)Arguments
cmdsA non-empty list of character vectors. Each vector is one command: the first element is the executable and the rest are its arguments. Example:
list(c("sort"), c("uniq", "-c")).stdinStandard input for the first process.
NULLto discard,"|"so the parent R process can write to it via$write_input(), or a file path.stdoutStandard output of the last process.
"|"(the default) so the parent R process can read from it,NULLto discard, or a file path.stderrStandard error for all processes.
NULL(the default) to discard,"|"to create a separate readable pipe per process,"2>&1"to merge into stdout, or a file path. When"|", use$read_error()to read from the last process; use$get_processes()to access individual process objects for other processes.envEnvironment variables for all processes, or
NULLto inherit the parent environment.encodingAssumed encoding for stdin/stdout/stderr streams.
wdWorking directory for all processes, or
NULLfor the current directory.cleanupWhether to kill the processes on garbage collection.
cleanup_treeWhether to kill the full process trees on garbage collection.
Method print()
Print the pipeline to the screen.