trim: Trim an R Object

Description Usage Arguments Examples

View source: R/trim.R

Description

Trims an R object whilst presuming the results of a given function call, where the R object is given as an argument. One popular example could be trimming an R model object whilst presuming the results of the predict function on a sample of data.

Usage

1
2
3
trim(obj, obj_arg_name = NULL, fun = predict, size_target = 0,
  tolerate_warnings = FALSE, verbose = TRUE, dont_touch = list(),
  ...)

Arguments

obj

list R object to be trimmed. _MUST_ inherit from the 'list' class.

obj_arg_name

character what is the name of the parameter, that 'obj' must be set to, when invoking 'fun'. Defaults to NULL, in which case the function assumes, that the 'obj' matches the first parameter of 'fun'.

fun

function function that must return the same results, when invoked with 'obj' both before and after trimming.

size_target

numeric desired maximum size in _MegaBytes_ of object after trimming has been conducted. When this size is achieved, the trimming stops. Defaults to 0, in which case trimming continues, until no further trimming can be done without breaking results from 'fun'.

tolerate_warnings

logical tolerate warnings (=TRUE) Or not (=FALSE) from function call results?

verbose

logical print messages?

dont_touch

list list with name indices of elements, that must not be removed from object by trimming procedure.

...

other (named) arguments for 'fun'.

Examples

1
2
3
4
5
6
7
8
# get training data for predictive model.
trn <- datasets::mtcars

# estimate model.
mdl <- lm(mpg ~ ., data = trn)
trim(obj = mdl, obj_arg_name = "object", fun = predict, newdata = trn)
trim(obj = mdl, obj_arg_name = "object", fun = predict, newdata = trn,
dont_touch = list(c("model"), c("qr","tol")))

trimmer documentation built on Dec. 19, 2019, 5:07 p.m.