diff --git a/DESCRIPTION b/DESCRIPTION index 5b05cdd8f..18d089fed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -89,37 +89,39 @@ Imports: storr (>= 1.1.0), utils Suggests: - abind, - bindr, - callr, - cli (>= 1.1.0), - clustermq (>= 0.8.8), - crayon, - curl (>= 2.7), - datasets, - downloader, - future, - ggplot2, - ggraph, - grDevices, - knitr, - lubridate, - networkD3, - parallel, - prettycode, - Rcpp, - rmarkdown, - rstudioapi, - stats, - styler, - testthat (>= 2.1.0), - tibble, - tidyselect (>= 0.2.4), - txtq (>= 0.1.2), - txtplot, - usethis, - visNetwork, - webshot + abind, + bindr, + callr, + cli (>= 1.1.0), + clustermq (>= 0.8.8), + crayon, + curl (>= 2.7), + datasets, + downloader, + future, + ggplot2, + ggraph, + grDevices, + knitr, + lubridate, + networkD3, + parallel, + prettycode, + Rcpp, + rmarkdown, + rstudioapi, + stats, + styler, + testthat (>= 2.1.0), + tibble, + tidyselect (>= 0.2.4), + txtq (>= 0.1.3), + txtplot, + usethis, + visNetwork, + webshot +Remotes: + wlandau/txtq VignetteBuilder: knitr Encoding: UTF-8 Language: en-US diff --git a/R/api-history.R b/R/api-history.R index 394d971ed..25a3072cd 100644 --- a/R/api-history.R +++ b/R/api-history.R @@ -33,7 +33,7 @@ #' d$x2 <- d$x ^ 3 #' lm(y ~ x2, data = d) #' } -#' Sys.sleep(1.1) +#' Sys.sleep(0.01) #' make(my_plan, history = TRUE, verbose = 0L) #' # The history is a data frame about all the recorded runs of your targets. #' out <- drake_history(analyze = TRUE) @@ -88,9 +88,8 @@ drake_history <- function( command = out$command, runtime = out$runtime ) - ref <- as.POSIXct("0000-01-01", origin = "0000-01-01") - out <- out[order(out$target, ref - out$time), ] - out$latest <- !duplicated(out$target) + out <- out[order(out$target, out$time), ] + out$latest <- !duplicated(out$target, fromLast = TRUE) if (analyze) { args <- lapply(out$command, find_args) args <- do.call(drake_bind_rows, args) diff --git a/R/utils-utils.R b/R/utils-utils.R index 02b39ff34..095a2c756 100644 --- a/R/utils-utils.R +++ b/R/utils-utils.R @@ -451,6 +451,6 @@ make_unique <- function(x) { y[order(ord)] } -microtimestamp <- function() { - format(Sys.time(), "%Y-%m-%d %H:%M:%OS9") +microtime <- function() { + format(Sys.time(), "%Y-%m-%d %H:%M:%OS9 %z GMT") } diff --git a/R/vis-console.R b/R/vis-console.R index 2422fc743..478fe9f69 100644 --- a/R/vis-console.R +++ b/R/vis-console.R @@ -35,7 +35,7 @@ drake_log <- function(..., target = character(0), config) { "|", Sys.getpid(), "|", - microtimestamp(), + microtime(), "|", target, "|", diff --git a/man/drake_history.Rd b/man/drake_history.Rd index a02dd6915..9e57dd0d0 100644 --- a/man/drake_history.Rd +++ b/man/drake_history.Rd @@ -4,7 +4,7 @@ \alias{drake_history} \title{Show history} \usage{ -drake_history(cache = NULL, history = NULL, show_args = FALSE, +drake_history(cache = NULL, history = NULL, analyze = FALSE, make_imports = TRUE, do_prework = TRUE, verbose = TRUE) } \arguments{ @@ -19,8 +19,9 @@ produced by \code{make(history = TRUE)}. If not supplied, \code{drake} will try to find it next to the cache in a folder called \code{.drake_history/}.} -\item{show_args}{Logical, whether to search for named atomic arguments -to function calls inside \code{\link[=drake_plan]{drake_plan()}} commands. +\item{analyze}{Logical, whether to analyze \code{\link[=drake_plan]{drake_plan()}} +commands for named atomic arguments to function calls. +The values of these arguments will show up in the return value. Could be slow because this requires parsing and analyzing lots of R code.} @@ -50,15 +51,33 @@ and whether each target is up to date (also could be slow). \examples{ \dontrun{ isolate_example({ -load_mtcars_example( -make(my_plan, history = TRUE) +# First, let's iterate on a drake workflow. +load_mtcars_example() +make(my_plan, history = TRUE, verbose = 0L) +# Naturally, we'll make updates to our targets along the way. reg2 <- function(d) { d$x2 <- d$x ^ 3 lm(y ~ x2, data = d) } -Sys.sleep(5) -make(my_plan, history = TRUE) -drake_history(show_args = TRUE) +Sys.sleep(0.01) +make(my_plan, history = TRUE, verbose = 0L) +# The history is a data frame about all the recorded runs of your targets. +out <- drake_history(analyze = TRUE) +print(out) +# View(out) +# Let's use the history to recover the oldest version +# of our regression2_small target. +oldest_reg2_small <- max(which(out$target == "regression2_small")) +hash_oldest_reg2_small <- out[oldest_reg2_small, ]$hash +cache <- drake_cache() +cache$get_value(hash_oldest_reg2_small) +# If you run clean(), drake can still find all the targets. +clean(small) +drake_history() +# But if you run clean() with garbage collection, +# older versions of your targets may be gone. +clean(large, garbage_collection = TRUE) +drake_history() }) } } diff --git a/tests/testthat/test-history.R b/tests/testthat/test-history.R index 8309634de..312d46f86 100644 --- a/tests/testthat/test-history.R +++ b/tests/testthat/test-history.R @@ -5,7 +5,6 @@ test_with_dir("history with no cache", { }) test_with_dir("basic history", { - skip_on_cran() skip_if_not_installed("txtq") # Iterate. load_mtcars_example() @@ -15,7 +14,7 @@ test_with_dir("basic history", { d$x2 <- d$x ^ 3 lm(y ~ x2, data = d) } - Sys.sleep(1.1) + Sys.sleep(0.01) make(my_plan, history = TRUE, cache = cache, session_info = FALSE) # Get and inspect the history. @@ -59,3 +58,19 @@ test_with_dir("basic history", { expect_na <- out$target == "small" | !out$latest expect_equal(is.na(out$hash), expect_na) }) + +test_with_dir("complicated history commands", { + skip_if_not_installed("txtq") + plan <- drake_plan( + a = identity( + x = list(a = "x", 2, b = list(y = 3L, z = sqrt(4), w = "5")) + ) + ) + cache <- storr::storr_environment() + make(plan, cache = cache, session_info = FALSE, history = TRUE) + out <- drake_history(cache = cache, analyze = TRUE) + expect_equal(ncol(out), 10L) + expect_equal(out$a, "x") + expect_equal(out$w, "5") + expect_equal(out$y, 3L) +})