iterchunks | R Documentation |
Generate a iterator along chunks of a vector
iterchunks(x, nchunks)
x |
A vector. |
nchunks |
Number of chunks. |
## Not run:
library(BiocParallel)
x <- 1:100
BPPARAM <- bpparam()
bpprogressbar(BPPARAM) <- TRUE
bpworkers(BPPARAM) <- 10
slow_fun <- function(x) {
out <- NULL
for (i in seq_along(x)) {
Sys.sleep(0.5)
out[[i]] <- x[[i]] + 3
}
return(out)
}
system.time({
res0 <- lapply(x, FUN = slow_fun)
})
unlist(res0, recursive = FALSE, use.names = FALSE)[71:73]
system.time({
res1 <- bplapply(x, FUN = slow_fun, BPPARAM = BPPARAM)
})
unlist(res1, recursive = FALSE, use.names = FALSE)[71:73]
system.time({
res2 <- bplapply(tochunks(x, nchunks = bpworkers(BPPARAM)), FUN = slow_fun, BPPARAM = BPPARAM)
})
unlist(res2, recursive = FALSE, use.names = FALSE)[71:73]
system.time({
res3 <- bpiterate(ITER = iterchunks(x, nchunks = bpworkers(BPPARAM)), FUN = slow_fun, BPPARAM = BPPARAM)
})
unlist(res3, recursive = FALSE, use.names = FALSE)[71:73]
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.