@@ -17,21 +17,33 @@ transform_files <- function(files, transformers, include_roxygen_examples, base_
17
17
max_char <- min(max(nchar(files ), 0 ), getOption(" width" ))
18
18
len_files <- length(files )
19
19
if (len_files > 0L && ! getOption(" styler.quiet" , FALSE )) {
20
- cat(" Styling " , len_files , " files:\n " )
20
+ cat(" Styling " , len_files , " files:\n " ) # TODO should only have one space between words
21
21
}
22
22
23
- if (! identical(Sys.getenv(" TESTTHAT" ), " true" ) && rlang :: is_installed(" furrr" )) {
24
- if (inherits(future :: plan(), " uniprocess" )) {
23
+ future_strategy_no_override <- tolower(Sys.getenv(" R_STYLER_FUTURE_NO_OVERRIDE" , " FALSE" )) == " true"
24
+ if (rlang :: is_installed(" furrr" )) {
25
+ # only parallelise when furrr is installed
26
+ if (! future_strategy_no_override && length(files ) > 2 ) {
27
+ # only override when env not set and more than two files.
25
28
local_options(future.supportsMulticore.unstable = " quiet" )
26
- oplan <- future :: plan(" multiprocess" )
27
- on.exit(future :: plan(oplan ), add = TRUE )
28
- }
29
+ oplan <- future :: plan(" multisession" ) # not sure we should use
29
30
31
+ # withr::defer() gives C stack overflow on macOS, on.exit not.
32
+ on.exit(future :: plan(oplan ), add = TRUE , after = FALSE )
33
+ }
30
34
changed <- furrr :: future_map_lgl(files , transform_file ,
31
35
fun = transformer , max_char_path = max_char , dry = dry ,
32
36
.progress = TRUE
33
37
)
34
38
} else {
39
+ if (future_strategy_no_override ) {
40
+ rlang :: warn(paste(
41
+ " Environment variable `R_STYLER_FUTURE_NO_OVERRIDE` is not respected" ,
42
+ " because package {furrr} is not installed. Falling back to " ,
43
+ " `purrr::map_lgl()` to iterate over files to style instead of" ,
44
+ " `furrr::future_map_lgl()`."
45
+ ))
46
+ }
35
47
changed <- map_lgl(files , transform_file ,
36
48
fun = transformer , max_char_path = max_char , dry = dry
37
49
)
0 commit comments