Skip to content

Commit

Permalink
Parallel styling
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 20, 2020
1 parent c50338f commit 77806a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Suggests:
data.tree (>= 0.1.6),
digest,
dplyr,
furrr,
future,
here,
knitr,
prettycode,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 18 additions & 3 deletions R/transform-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
Expand Down

0 comments on commit 77806a3

Please sign in to comment.