From 73bf9a7a0bb6bb0c0aeb7e79d4dd8af25ffd2139 Mon Sep 17 00:00:00 2001 From: Witold Wolski Date: Tue, 24 Sep 2024 10:38:59 +0200 Subject: [PATCH] nested --- R/tidyMS_aggregation.R | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/R/tidyMS_aggregation.R b/R/tidyMS_aggregation.R index 24c25284..7343997c 100644 --- a/R/tidyMS_aggregation.R +++ b/R/tidyMS_aggregation.R @@ -581,15 +581,21 @@ estimate_intensity <- function(data, config, .func) config <- config$clone(deep = TRUE) xnested <- data |> group_by_at(config$table$hierarchy_keys_depth()) |> nest() - pb <- progress::progress_bar$new(total = nrow(xnested)) - message("starting aggregation") - res <- vector( mode = "list" , length = nrow(xnested) ) - for (i in seq_len(nrow(xnested))) { - pb$tick() - aggr <- .func(xnested$data[[i]], config) - res[[i]] <- .reestablish_condition(xnested$data[[i]], aggr , config) + + loopOverNested <- function (xnested, .func, config) { + pb <- progress::progress_bar$new(total = nrow(xnested)) + message("starting aggregation") + res <- vector( mode = "list" , length = nrow(xnested) ) + for (i in seq_len(nrow(xnested))) { + pb$tick() + aggr <- .func(xnested$data[[i]], config) + res[[i]] <- .reestablish_condition(xnested$data[[i]], aggr , config) + } } + + res <- loopOverNested(xnested, .func = .func , config = config) + xnested[[makeName]] <- res newconfig <- make_reduced_hierarchy_config( config,