splitted_mutate: splitted_mutate

View source: R/splitted_mutate.R

splitted_mutateR Documentation

splitted_mutate

Description

Splits the data.frame into separeta parts and evaluates it one-by-one. Useful for saving memmory during large computations.

Usage

splitted_mutate(.data, ..., split_number = 100, .keep = NULL, .progress = TRUE)

Arguments

.data

Data frame.

...

arguments to pass mutate(...).

split_number

Number of parts to split the data.frame before evaluation.

.keep

Variables to keep after eval the expression. Original columns are keept automaticly.

cores

Number of cores to use. If cores = 1 (default) then evaluation is made by simple for loop.

Value

.data overview_print

Examples


iris_samples <- tibble(data = replicate(100, sample_n(iris, 50), simplify = FALSE))

iris_samples

iris_samples %>%
 splitted_mutate(
   fit = map(data, lm, formula = Sepal.Length ~ Sepal.Width),
   coefs = map(fit, "coefficients"),
   coef1 = map_dbl(coefs, 1),
   coef2 = map_dbl(coefs, 2),
   .keep = c("coef1", "coef2") # single core
 )

iris_samples %>%
 splitted_mutate(
   fit = map(data, lm, formula = Sepal.Length ~ Sepal.Width),
   coefs = map(fit, "coefficients"),
   coef1 = map_dbl(coefs, 1),
   coef2 = map_dbl(coefs, 2),
   .keep = c("coef1", "coef2"),
   cores = 6 # multicore evaluation
 )


MarcellGranat/granatlib documentation built on July 9, 2023, 6:08 a.m.