diff --git a/DESCRIPTION b/DESCRIPTION index ce0163f13..5040b725c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -108,4 +108,4 @@ VignetteBuilder: knitr Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 6.1.0 +RoxygenNote: 6.1.1 diff --git a/NEWS.md b/NEWS.md index 89154e93f..69d8f5bed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ - **Large speed boost**: reduce repeated calls to `parse()` in `code_dependencies()`. - **Large speed boost**: change the default value of `memory_strategy` (previously `pruning_strategy`) to `"speed"` (previously `"lookahead"`). +- Compute a special data structure in `drake_config()` (`config$ordinances`) just to store the code analysis results. This is an intermediate structure between the workflow plan data frame and the graph. It will help clean up the internals in future development. +- Improve memoized preprocessing: deparse all the functions in the environment so the memoization does not react so spurious changes in R internals. Related: #345. - Remove strict dependencies on packages `evaluate`, `fs`, `future`, `magrittr`, `parallel`, `R.utils`, `stats`, and `stringi`. - Deprecate the `force` argument to `make()` and related functions. - Change the name of `prune_envir()` to `manage_memory()`. diff --git a/R/create_drake_ordinances.R b/R/create_drake_ordinances.R index 3dd6138c8..bdd94d519 100644 --- a/R/create_drake_ordinances.R +++ b/R/create_drake_ordinances.R @@ -20,14 +20,15 @@ create_drake_ordinances <- function( trigger = parse_trigger(trigger = trigger, envir = envir), globals = sort(c(plan$target, ls(envir = envir, all.names = TRUE))) ) - imports <- cdn_prepare_imports(config) + imports <- cdo_prepare_imports(config) + imports_kernel <- cdo_imports_kernel(config, imports) import_ordinances <- memo_expr( - cdn_analyze_imports(config, imports), + cdo_analyze_imports(config, imports), config$cache, - imports + imports_kernel ) command_ordinances <- memo_expr( - cdn_analyze_commands(config), + cdo_analyze_commands(config), config$cache, config$plan, config$trigger, @@ -37,10 +38,10 @@ create_drake_ordinances <- function( c(import_ordinances, command_ordinances) } -cdn_prepare_imports <- function(config) { +cdo_prepare_imports <- function(config) { console_preprocess(text = "analyze environment", config = config) imports <- as.list(config$envir) - cdn_unload_conflicts( + cdo_unload_conflicts( imports = names(imports), targets = config$plan$target, envir = config$envir, @@ -50,7 +51,7 @@ cdn_prepare_imports <- function(config) { imports[import_names] } -cdn_unload_conflicts <- function(imports, targets, envir, verbose) { +cdo_unload_conflicts <- function(imports, targets, envir, verbose) { common <- intersect(imports, targets) if (verbose & length(common)) { message( @@ -61,7 +62,22 @@ cdn_unload_conflicts <- function(imports, targets, envir, verbose) { remove(list = common, envir = envir) } -cdn_analyze_imports <- function(config, imports) { +cdo_imports_kernel <- function(config, imports) { + out <- lightly_parallelize( + X = imports, + FUN = function(x) { + if (is.function(x)) { + x <- deparse(x) + } + x + }, + jobs = config$jobs + ) + names(out) <- names(imports) + out[sort(names(out))] +} + +cdo_analyze_imports <- function(config, imports) { names <- names(imports) console_many_targets( targets = names, @@ -88,7 +104,7 @@ cdn_analyze_imports <- function(config, imports) { out } -cdn_analyze_commands <- function(config) { +cdo_analyze_commands <- function(config) { console_many_targets( targets = config$plan$target, pattern = "analyze", @@ -115,7 +131,7 @@ cdn_analyze_commands <- function(config) { ) out <- lightly_parallelize( X = ordinances, - FUN = cdn_prepare_ordinance, + FUN = cdo_prepare_ordinance, jobs = config$jobs, config = config ) @@ -123,7 +139,7 @@ cdn_analyze_commands <- function(config) { out } -cdn_prepare_ordinance <- function(ordinance, config){ +cdo_prepare_ordinance <- function(ordinance, config){ ordinance$deps_build <- command_dependencies( command = ordinance$command, exclude = ordinance$target,