encapsulate {mlr3misc}R Documentation

Encapsulate Function Calls for Logging

Description

Evaluates a function while both recording an output log and measuring the elapsed time. There are currently three different modes implemented to encapsulate a function call:

Usage

encapsulate(method, .f, .args = list(), .opts = list(),
  .pkgs = character(), .seed = NA_integer_)

Arguments

method

:: character(1)
One of "none", "evaluate" or "callr".

.f

:: function()
Function to call.

.args

:: list()
Arguments passed to .f.

.opts

:: named list()
Options to set for the function call. Options get reset on exit.

.pkgs

:: character()
Packages to load (not attach).

.seed

:: integer(1)
Random seed to set before invoking the function call. Gets reset to the previous seed on exit.

Value

(named list()) with three fields:

Examples

f = function(n) {
  message("hi from f")
  if (n > 5) {
    stop("n must be <= 5")
  }
  runif(n)
}
encapsulate("none", f, list(n = 1), .seed = 1)
encapsulate("evaluate", f, list(n = 1), .seed = 1)
encapsulate("callr", f, list(n = 1), .seed = 1)

[Package mlr3misc version 0.1.3 Index]