Skip to content

Commit

Permalink
Work on #136
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Nov 5, 2017
1 parent c571d75 commit 2cf0d4d
Show file tree
Hide file tree
Showing 27 changed files with 199 additions and 104 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(default_Makefile_command)
export(default_cache_path)
export(default_cache_type)
export(default_graph_title)
export(default_hook)
export(default_long_hash_algo)
export(default_parallelism)
export(default_recipe_command)
Expand Down
4 changes: 1 addition & 3 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ config <- function(
targets = drake::possible_targets(plan),
envir = parent.frame(),
verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(verbose = verbose, force = force),
parallelism = drake::default_parallelism(),
jobs = 1,
Expand Down
9 changes: 6 additions & 3 deletions R/current.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ file_current <- function(target, meta, config){
if (!file.exists(unquote(target))){
return(FALSE)
}
identical(
config$cache$get(target, namespace = "kernels"),
meta$file
tryCatch(
identical(
config$cache$get(target, namespace = "kernels"),
meta$file
),
error = error_false
)
}

Expand Down
32 changes: 17 additions & 15 deletions R/dataframes_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@
#' \code{build_times}, \code{digits}, \code{targets_only},
#' \code{split_columns}, and \code{font_size}.
#'
#' @param from_scratch logical, whether to assume that
#' all targets are out of date and the next \code{\link{make}()}
#' will happen from scratch. Setting to \code{TRUE} will prevent
#' the graph from showing you which targets are up to date,
#' but it makes computing the graph much faster.
#' @param make_imports logical, whether to import external files
#' and objects from the user's workspace to detemine
#' which targets are up to date. If \code{FALSE}, the computation
#' is faster, but all the relevant information is drawn from the cache
#' and may be out of date.
#'
#' @param from_scratch deprecated: use \code{make_imports} instead.
#'
#' @examples
#' \dontrun{
Expand All @@ -128,17 +130,22 @@
dataframes_graph <- function(
plan = workplan(), targets = drake::possible_targets(plan),
envir = parent.frame(), verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(verbose = verbose), jobs = 1,
parallelism = drake::default_parallelism(), packages = rev(.packages()),
prework = character(0), build_times = TRUE, digits = 3,
targets_only = FALSE,
split_columns = FALSE, font_size = 20, config = NULL,
from = NULL, mode = c("out", "in", "all"), order = NULL, subset = NULL,
from_scratch = FALSE
make_imports = TRUE,
from_scratch = NULL
) {
if (!is.null(from_scratch)){
warning(
"Argument 'from_scratch' is deprecated. Using 'make_imports' instead."
)
}

force(envir)
if (is.null(config)){
config <- config(plan = plan, targets = targets,
Expand All @@ -153,12 +160,7 @@ dataframes_graph <- function(

config$plan <- sanitize_plan(plan = plan)
config$targets <- sanitize_targets(plan = plan, targets = targets)

if (from_scratch){
config$outdated <- plan$target
} else {
config$outdated <- outdated(config = config)
}
config$outdated <- outdated(config = config, make_imports = make_imports)

network_data <- visNetwork::toVisNetworkData(config$graph)
config$nodes <- network_data$nodes
Expand Down
6 changes: 2 additions & 4 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ is_parsable <- Vectorize(function(x){
parse(text = x)
TRUE
},
error = function(e){
FALSE
}
error = error_false
)
},
"x")
Expand All @@ -221,7 +219,7 @@ extract_filenames <- function(command){
}

safe_grepl <- function(pattern, x){
tryCatch(grepl(pattern, x), error = function(e) FALSE)
tryCatch(grepl(pattern, x), error = error_false)
}

is_file <- function(x){
Expand Down
11 changes: 11 additions & 0 deletions R/handlers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error_character0 <- function(e){
character(0)
}

error_false <- function(e){
FALSE
}

error_na <- function(e){
NA
}
21 changes: 18 additions & 3 deletions R/hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,28 @@ output_sink_hook <- function(code){
#' @description a \code{hook} argument to \code{\link{make}()}
#' for which no targets get built and no imports get resolved
#' @export
#' @param code Placeholder for the code to build a target/import.
#' For \code{empty_hook}, this code does not actually get executed.
#' @examples
#' \dontrun{
#' load_basic_example()
#' make(my_plan, hook = empty_hook)
#' make(my_plan, hook = empty_hook) # Nothing gets built!
#' cached() # character(0)
#' }
#' @param code Placeholder for the code to build a target/import.
#' For \code{empty_hook}, this code does not actually get executed.
empty_hook <- function(code){
invisible()
}

#' @title Function default_hook
#' @description The default \code{hook} argument to \code{\link{make}()}.
#' @export
#' @param code Placeholder for the code to build a target/import.
#' @examples
#' \dontrun{
#' load_basic_example()
#' make(my_plan, hook = default_hook) # Nothing gets built!
#' cached() # character(0)
#' }
default_hook <- function(code){
force(code)
}
4 changes: 1 addition & 3 deletions R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ found_loadd_readd <- function(x){
get_specific_arg <- function(args, name){
tryCatch(
eval(args[[name]]),
error = function(e){
character(0)
}
error = error_character0
)
}

Expand Down
4 changes: 1 addition & 3 deletions R/make.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ make <- function(
targets = drake::possible_targets(plan),
envir = parent.frame(),
verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(verbose = verbose, force = force),
parallelism = drake::default_parallelism(),
jobs = 1,
Expand Down
12 changes: 12 additions & 0 deletions R/migrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
#' tells you whether the migration
#' is successful. If it is not successful, \code{migrate()} tells you where
#' it backed up your old project.
#' @examples
#' \dontrun{
#' # With drake 4.3.0:
#' load_basic_example()
#' make(my_plan)
#' # Now, install drake >= 5.0.0
#' load_basic_example()
#' make(my_plan) # Error: cache is not back compatible.
#' migrate() # Convert the project's '.drake/' cache to the new format.
#' make(my_plan) # Everything is still up to date!
#' # Outdated objects from before migration will remain out of date afterwards.
#' }
migrate <- function(path = drake::default_cache_path(), jobs = 1){
cache <- should_migrate(path = path)
if (is.null(cache)){
Expand Down
19 changes: 11 additions & 8 deletions R/outdated.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@
#' Overrides all the other arguments if not \code{NULL}.
#' For example,
#' \code{plan} is replaced with \code{config$plan}.
#' Computing \code{config}
#' in advance could save time if you plan multiple calls to
#' \code{outdated()}.
#' @param make_imports logical, whether to import external files
#' and objects from the user's workspace to detemine
#' which targets are up to date. If \code{FALSE}, the computation
#' is faster, but all the relevant information is drawn from the cache
#' and may be out of date.
outdated <- function(
plan = workplan(),
targets = drake::possible_targets(plan),
envir = parent.frame(),
verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(verbose = verbose),
parallelism = drake::default_parallelism(),
jobs = 1,
packages = rev(.packages()),
prework = character(0),
config = NULL
config = NULL,
make_imports = TRUE
){
force(envir)
if (is.null(config)){
Expand All @@ -64,7 +65,9 @@ outdated <- function(
prework = prework
)
}
make_imports(config = config)
if (make_imports){
make_imports(config = config)
}
config <- quick_inventory(config)
all_targets <- intersect(V(config$graph)$name, config$plan$target)
meta_list <- meta_list(targets = all_targets, config = config)
Expand Down
15 changes: 10 additions & 5 deletions R/parallel_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ default_parallelism <- function() {
#' \item{'none'}{: Ignore all the imports and just focus on the max number
#' of useful jobs for parallelizing targets.}
#' }
#'
#' @param make_imports logical, whether to import external files
#' and objects from the user's workspace to detemine
#' which targets are up to date. If \code{FALSE}, the computation
#' is faster, but all the relevant information is drawn from the cache
#' and may be out of date.
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -218,13 +224,12 @@ max_useful_jobs <- function(
plan = workplan(), from_scratch = FALSE,
targets = drake::possible_targets(plan),
envir = parent.frame(), verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(verbose = verbose),
jobs = 1, parallelism = drake::default_parallelism(),
packages = rev(.packages()), prework = character(0), config = NULL,
imports = c("files", "all", "none")
imports = c("files", "all", "none"),
make_imports = TRUE
){
force(envir)
if (is.null(config)){
Expand All @@ -243,7 +248,7 @@ max_useful_jobs <- function(
}
config <- quick_inventory(config)
nodes <- dataframes_graph(plan = config$plan, config = config,
split_columns = FALSE)$nodes
split_columns = FALSE, make_imports = make_imports)$nodes
imports <- match.arg(imports)
just_targets <- intersect(nodes$id, config$plan$target)
just_files <- Filter(x = nodes$id, f = is_file)
Expand Down
21 changes: 11 additions & 10 deletions R/plotgraph.R → R/plot_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@
#'
#' @param ncol_legend number of columns in the legend nodes
#'
#' @param from_scratch logical, whether to assume that
#' all targets are out of date and the next \code{\link{make}()}
#' will happen from scratch. Setting to \code{TRUE} will prevent
#' the graph from showing you which targets are up to date,
#' but it makes computing the graph much faster.
#' @param make_imports logical, whether to import external files
#' and objects from the user's workspace to detemine
#' which targets are up to date. If \code{FALSE}, the computation
#' is faster, but all the relevant information is drawn from the cache
#' and may be out of date.
#'
#' @param from_scratch Deprecated. Use \code{make_imports} instead.
#'
#' @param ... other arguments passed to
#' \code{visNetwork::visNetwork()} to plot the graph.
Expand All @@ -157,9 +159,7 @@
plot_graph <- function(
plan = workplan(), targets = drake::possible_targets(plan),
envir = parent.frame(), verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(verbose = verbose),
jobs = 1, parallelism = drake::default_parallelism(),
packages = rev(.packages()), prework = character(0),
Expand All @@ -173,7 +173,8 @@ plot_graph <- function(
from = NULL, mode = c("out", "in", "all"), order = NULL,
subset = NULL,
ncol_legend = 1,
from_scratch = FALSE,
make_imports = TRUE,
from_scratch = NULL,
...
){
force(envir)
Expand All @@ -186,7 +187,7 @@ plot_graph <- function(
targets_only = targets_only, split_columns = split_columns,
config = config, font_size = font_size,
from = from, mode = mode, order = order, subset = subset,
from_scratch = from_scratch
make_imports = make_imports, from_scratch = from_scratch
)
if (is.null(main)){
main <- raw_graph$default_title
Expand Down
8 changes: 2 additions & 6 deletions R/predict_runtime.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ predict_runtime <- function(
targets = drake::possible_targets(plan),
envir = parent.frame(),
verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(path = path, search = search, verbose = verbose),
parallelism = drake::default_parallelism(),
jobs = 1,
Expand Down Expand Up @@ -224,9 +222,7 @@ rate_limiting_times <- function(
targets = drake::possible_targets(plan),
envir = parent.frame(),
verbose = TRUE,
hook = function(code){
force(code)
},
hook = default_hook,
cache = drake::get_cache(path = path, search = search, verbose = verbose),
parallelism = drake::default_parallelism(),
jobs = 1,
Expand Down
4 changes: 2 additions & 2 deletions man/config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions man/dataframes_graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2cf0d4d

Please sign in to comment.