Skip to content

Commit 44ca6d1

Browse files
committed
progress bar for subsets
1 parent a8f2f23 commit 44ca6d1

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

R/map.r

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ map = function(X, along, FUN, subsets=base::rep(1,dim(X)[along]), drop=TRUE, ...
2626
subs_idx[[i]][[along]] = (subsets==lsubsets[i])
2727

2828
# for each subset, call map_one
29-
resultList = lapply(subs_idx, function(f)
30-
map_one(subset(X, f), along, FUN, drop=FALSE, ...))
29+
pb = pb(nsubsets)
30+
resultList = lapply(subs_idx, function(f) {
31+
re = map_one(subset(X, f), along, FUN, drop=FALSE, ...)
32+
pb$tick()
33+
re
34+
})
3135

3236
# assemble results together
3337
Y = bind(resultList, along=along)
@@ -44,10 +48,11 @@ map = function(X, along, FUN, subsets=base::rep(1,dim(X)[along]), drop=TRUE, ...
4448
#' @param X An n-dimensional array
4549
#' @param along Along which axis to apply the function
4650
#' @param FUN A function that maps a vector to the same length or a scalar
51+
#' @param pb progress bar object
4752
#' @param drop Remove unused dimensions after mapping; default: TRUE
4853
#' @param ... Arguments passed to the function
4954
#' @return An array where \code{FUN} has been applied
50-
map_one = function(X, along, FUN, drop=TRUE, ...) {
55+
map_one = function(X, along, FUN, pb, drop=TRUE, ...) {
5156
if (is.vector(X) || length(dim(X))==1)
5257
return(FUN(X, ...))
5358

man/map_one.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)