diff --git a/DESCRIPTION b/DESCRIPTION index 63b0479fd..0dcfe7f32 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,6 +33,8 @@ Suggests: data.tree (>= 0.1.6), digest, dplyr, + furrr, + future, here, knitr, prettycode, diff --git a/NAMESPACE b/NAMESPACE index 67f3fcd43..88f12cd8d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,6 +39,7 @@ importFrom(purrr,when) importFrom(rlang,abort) importFrom(rlang,is_empty) importFrom(rlang,is_installed) +importFrom(rlang,local_options) importFrom(rlang,seq2) importFrom(rlang,warn) importFrom(rlang,with_handlers) diff --git a/R/transform-files.R b/R/transform-files.R index d21ce666c..649c25845 100644 --- a/R/transform-files.R +++ b/R/transform-files.R @@ -11,6 +11,7 @@ #' styling whether or not it was actually changed (or would be changed when #' `dry` is not "off"). #' @keywords internal +#' @importFrom rlang local_options transform_files <- function(files, transformers, include_roxygen_examples, base_indention, dry) { transformer <- make_transformer(transformers, include_roxygen_examples, base_indention) max_char <- min(max(nchar(files), 0), getOption("width")) @@ -19,9 +20,23 @@ transform_files <- function(files, transformers, include_roxygen_examples, base_ cat("Styling ", len_files, " files:\n") } - changed <- map_lgl(files, transform_file, - fun = transformer, max_char_path = max_char, dry = dry - ) + if (rlang::is_installed("furrr")) { + if (inherits(future::plan(), "uniprocess")) { + local_options(future.supportsMulticore.unstable = "quiet") + oplan <- future::plan("multiprocess") + on.exit(future::plan(oplan), add = TRUE) + } + + changed <- furrr::future_map_lgl(files, transform_file, + fun = transformer, max_char_path = max_char, dry = dry, + .progress = TRUE + ) + } else { + changed <- map_lgl(files, transform_file, + fun = transformer, max_char_path = max_char, dry = dry + ) + } + communicate_summary(changed, max_char) communicate_warning(changed, transformers) new_tibble(list(file = files, changed = changed), nrow = len_files)