Skip to content

Commit 77806a3

Browse files
committed
Parallel styling
1 parent c50338f commit 77806a3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

DESCRIPTION

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Suggests:
3333
data.tree (>= 0.1.6),
3434
digest,
3535
dplyr,
36+
furrr,
37+
future,
3638
here,
3739
knitr,
3840
prettycode,

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ importFrom(purrr,when)
3939
importFrom(rlang,abort)
4040
importFrom(rlang,is_empty)
4141
importFrom(rlang,is_installed)
42+
importFrom(rlang,local_options)
4243
importFrom(rlang,seq2)
4344
importFrom(rlang,warn)
4445
importFrom(rlang,with_handlers)

R/transform-files.R

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#' styling whether or not it was actually changed (or would be changed when
1212
#' `dry` is not "off").
1313
#' @keywords internal
14+
#' @importFrom rlang local_options
1415
transform_files <- function(files, transformers, include_roxygen_examples, base_indention, dry) {
1516
transformer <- make_transformer(transformers, include_roxygen_examples, base_indention)
1617
max_char <- min(max(nchar(files), 0), getOption("width"))
@@ -19,9 +20,23 @@ transform_files <- function(files, transformers, include_roxygen_examples, base_
1920
cat("Styling ", len_files, " files:\n")
2021
}
2122

22-
changed <- map_lgl(files, transform_file,
23-
fun = transformer, max_char_path = max_char, dry = dry
24-
)
23+
if (rlang::is_installed("furrr")) {
24+
if (inherits(future::plan(), "uniprocess")) {
25+
local_options(future.supportsMulticore.unstable = "quiet")
26+
oplan <- future::plan("multiprocess")
27+
on.exit(future::plan(oplan), add = TRUE)
28+
}
29+
30+
changed <- furrr::future_map_lgl(files, transform_file,
31+
fun = transformer, max_char_path = max_char, dry = dry,
32+
.progress = TRUE
33+
)
34+
} else {
35+
changed <- map_lgl(files, transform_file,
36+
fun = transformer, max_char_path = max_char, dry = dry
37+
)
38+
}
39+
2540
communicate_summary(changed, max_char)
2641
communicate_warning(changed, transformers)
2742
new_tibble(list(file = files, changed = changed), nrow = len_files)

0 commit comments

Comments
 (0)