Skip to content

Instantly share code, notes, and snippets.

@bakaburg1
Last active March 17, 2019 12:24
Show Gist options
  • Save bakaburg1/7b34101e9fe9af9e8d389988490e23b2 to your computer and use it in GitHub Desktop.
Save bakaburg1/7b34101e9fe9af9e8d389988490e23b2 to your computer and use it in GitHub Desktop.
Very simple parallelized implementation of dplyr::do() using mclapply.
library(parallel)
library(pbmcapply)
library(dplyr)
mcdo <- function(.data, ...) {
if (progress.bar) {
pkg.require(c('pbmcapply'))
pfun <- pbmclapply
} else pfun <- mclapply
indices <- if ('grouped_df' %in% class(.data)) attr(.data, 'indices') else 1:nrow(.data)
pfun(indices, function(i) {
do(.data[i + 1,], ...)
}) %>% bind_rows()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment