Title: | Trim an Object |
---|---|
Description: | A lightweight toolkit to reduce the size of a list object. The object is minimized by recursively removing elements from the object one-by-one. The process is constrained by a reference function call specified by the user, where the target object is given as an argument. The procedure will not allow elements to be removed from the object, that will cause results from the function call to diverge from the function call with the original object. |
Authors: | Lars Kjeldgaard [aut, cre] |
Maintainer: | Lars Kjeldgaard <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.8.1 |
Built: | 2025-03-02 03:03:29 UTC |
Source: | https://github.com/smaakage85/trimmer |
Adjusts positions of all candidates for elimination in data.table after removing a candidate (due to the fact, that the positions may shift).
adjust_candidates(cand, cand_top_idx)
adjust_candidates(cand, cand_top_idx)
cand |
|
cand_top_idx |
|
data.table
candidates after any adjustments to position
indices of candidates.
Convert Numbered Index to Named Index of List Element
convert_idx_to_name(vec, obj)
convert_idx_to_name(vec, obj)
vec |
|
obj |
|
character
named index of list element.
d <- list(a = list(b = list(c = 3, d = 5), e = c(2,4))) num_idx <- c(1,1,2) convert_idx_to_name(num_idx, d)
d <- list(a = list(b = list(c = 3, d = 5), e = c(2,4))) num_idx <- c(1,1,2) convert_idx_to_name(num_idx, d)
Dette script gør det muligt at referere til kolonner i data frames ved hjælp af Non Standard Evaluation (NSE) i databehandlingspakker som data.table og dplyr, uden at dette medfører R CMD check notes angående "no visible binding for global variable". Navnene på de variable, der refereres til ved hjælp af NSE, skal blot angives i en vektor til funktionen globalVariables() nedenfor.
fix_undefined_global_vars()
fix_undefined_global_vars()
Dette er den anbefalede løsning fra CRAN.
Compute Results From Function Call with Object as Argument
get_results_for_object(obj, obj_arg_name, fun, ..., tolerate_warnings = TRUE)
get_results_for_object(obj, obj_arg_name, fun, ..., tolerate_warnings = TRUE)
obj |
|
obj_arg_name |
|
fun |
|
... |
other (named) arguments for 'fun'. |
tolerate_warnings |
|
results from function call.
Convert Size in Bytes to Print Friendly String
pf_obj_size(x, digits = 2)
pf_obj_size(x, digits = 2)
x |
|
digits |
|
character
priend friendly string.
pf_obj_size(10) pf_obj_size(1010) pf_obj_size(2e06)
pf_obj_size(10) pf_obj_size(1010) pf_obj_size(2e06)
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.
trim(obj, obj_arg_name = NULL, fun = predict, size_target = 0, tolerate_warnings = FALSE, verbose = TRUE, dont_touch = list(), ...)
trim(obj, obj_arg_name = NULL, fun = predict, size_target = 0, tolerate_warnings = FALSE, verbose = TRUE, dont_touch = list(), ...)
obj |
|
obj_arg_name |
|
fun |
|
size_target |
|
tolerate_warnings |
|
verbose |
|
dont_touch |
|
... |
other (named) arguments for 'fun'. |
# 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")))
# 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")))