Skip to content

Commit

Permalink
progress bar for subsets
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Aug 18, 2018
1 parent a8f2f23 commit 44ca6d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions R/map.r
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ map = function(X, along, FUN, subsets=base::rep(1,dim(X)[along]), drop=TRUE, ...
subs_idx[[i]][[along]] = (subsets==lsubsets[i])

# for each subset, call map_one
resultList = lapply(subs_idx, function(f)
map_one(subset(X, f), along, FUN, drop=FALSE, ...))
pb = pb(nsubsets)
resultList = lapply(subs_idx, function(f) {
re = map_one(subset(X, f), along, FUN, drop=FALSE, ...)
pb$tick()
re
})

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

Expand Down
4 changes: 3 additions & 1 deletion man/map_one.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44ca6d1

Please sign in to comment.