apply
match.fun
batcher <- function (X, FUN, batch_size, ...) { FUN <- match.fun(FUN) nBatches <- length(X)/batch_size nWholeBatches <- floor(nBatches) if (nWholeBatches < 1) { return(forceAndCall(1,FUN, X)) } else { p_list <- list() for (i in 1:nWholeBatches) { if (nWholeBatches > 1) { pb <- txtProgressBar(min = 1, max = nWholeBatches, style = 3) setTxtProgressBar(pb, i) } p_list[[i]] <- forceAndCall(1, FUN, X[((i - 1) * batch_size + 1):((i) * batch_size)]) } message("Doing final batch...") if (nBatches != nWholeBatches) { p_list[[i + 1]] <- forceAndCall(1, FUN, X[((i) * batch_size + 1):length(X)]) } return(p_list) } }
batcher(X = runif(1000), FUN = mean, batch_size = 10)
match.call(get, call("get", "abc", i = FALSE, p = 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.