r_tee: Run and tee R code

Description Usage Arguments Details

Description

Runs R code in an isolated session, writes output to the console and to a file.

Usage

1
r_tee(..., tee = character(), callback = NULL, show = TRUE)

Arguments

...

Arguments passed on to callr::r

func

Function object to call in the new R process. The function should be self-contained and only refer to other functions and use variables explicitly from other packages using the :: notation. The environment of the function is set to .GlobalEnv before passing it to the child process. Because of this, it is good practice to create an anonymous function and pass that to callr, instead of passing a function object from a (base or other) package. In particular

r(.libPaths)

does not work, because .libPaths is defined in a special environment, but

r(function() .libPaths())

works just fine.

args

Arguments to pass to the function. Must be a list.

libpath

The library path.

repos

The repos option. If NULL, then no repos option is set. This options is only used if user_profile or system_profile is set FALSE, as it is set using the system or the user profile.

stdout

The name of the file the standard output of the child R process will be written to. If the child process runs with the --slave option (the default), then the commands are not echoed and will not be shown in the standard output. Also note that you need to call print() explicitly to show the output of the command(s).

stderr

The name of the file the standard error of the child R process will be written to. In particular message() sends output to the standard error. If nothing was sent to the standard error, then this file will be empty. This can be the same file as stderr, although there is no guarantee that the lines will be in the correct chronological order.

error

What to do if the remote process throws an error. See details below.

cmdargs

Command line arguments to pass to the R process. Note that c("-f", rscript) is appended to this, rscript is the name of the script file to run. This contains a call to the supplied function and some error handling code.

show

Logical, whether to show the standard output on the screen while the child process is running. Note that this is independent of the stdout and stderr arguments. The standard error is not shown currently.

callback

A function to call for each line of the standard output and standard error from the child process. It works together with the show option; i.e. if show = TRUE, and a callback is provided, then the output is shown of the screen, and the callback is also called.

block_callback

A function to call for each block of the standard output and standard error. This callback is not line oriented, i.e. multiple lines or half a line can be passed to the callback.

spinner

Whether to snow a calming spinner on the screen while the child R session is running. By default it is shown if show = TRUE and the R session is interactive.

system_profile

Whether to use the system profile file.

user_profile

Whether to use the user's profile file.

env

Environment variables to set for the child process.

timeout

Timeout for the function call to finish. It can be a base::difftime object, or a real number, meaning seconds. If the process does not finish before the timeout period expires, then a system_command_timeout_error error is thrown. Inf means no timeout.

tee

[character]
Files to which output is written

callback

A function to call for each line of the standard output and standard error from the child process. It works together with the show option; i.e. if show = TRUE, and a callback is provided, then the output is shown of the screen, and the callback is also called.

show

[logical(1)]
Controls if standard output and standard error are shown on the console. Defaults to TRUE, if you need FALSE consider using callr::r() with the stdout and stderr arguments.

Details

The tee argument can contain relative or absolute paths. Nonexistant parent directories will be created.

ANSI escapes will be stripped automatically from the output via fansi::strip_sgr() if this package is available. This function forwards to callr::r().


krlmlr/tee documentation built on May 5, 2019, 2:42 a.m.