robust_system: Catch stderr and stdout from external application

Description Usage Arguments Details Value

Description

Function robust_system provide easy way how to catch stdout, stderr and exit status from external application. It builds on base::system2 and utilize it internally. It catch stdout and stderr of command ran by system2 by redirecting them into temporary file and reading them with readLines.

Usage

1
2
robust_system(command, args = character(), dir = NULL, keep_temp = FALSE,
  stdout_read = list(), stderr_read = list(), ...)

Arguments

command

external program to run, same as command in system2.

args

arguments for external program, same as args in system2.

dir

directory that will be used, if not specified, R's temporary directory is used.

keep_temp

if temporary files with stdout and stderr should be kept, if dir is specified, and was created by this function, it is deleted as well.

stdout_read

parameters to be passed to readLines function of stdout.

stderr_read

parameters to be passed to readLines function of stderr

...

other parameters passed to system2.

Details

Function robust_system works by redirecting stdout and stderr to temporary files, either in R's temporary directory, which is deleted after R's session ends, or in user specified directory.

Parameters command and args are directly passed to system2, as well as any other optional parameters passed as ....

If keep_temp=FALSE, temporary files are deleted, but directory is deleted only if it was created by this function. This makes function clean after itself, but might be problematic if used in parallel.

With stdout_read and stderr_read, you can pass additional parameters to readLines function, should as warn=TRUE, as readLines throw warning whenever line doesn't end with a newline.

Value

list with stdout, sderr, exit code and if keep_temp=TRUE path to temporary files.


J-Moravec/robustSystem documentation built on May 7, 2019, 6:46 a.m.