diff --git a/.Rbuildignore b/.Rbuildignore index 597dbe6..9f3fb46 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,5 @@ ^\.github$ \.*gcov$ ^TODO\.md$ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/R/orderly.R b/R/orderly.R index 58be2e0..8a60925 100644 --- a/R/orderly.R +++ b/R/orderly.R @@ -121,6 +121,10 @@ orderly_run <- function(name, parameters = NULL, envir = NULL, outpack::outpack_packet_use_dependency(dat$depends$id[[i]], dat$depends$files[[i]]) } + packet <- outpack::outpack_packet_current() + lapply(packet$depends, function(dependency) { + expected <- c(expected, dependency$files$here) + }) ## TODO: if run fails we might not close out the device stack ## here, we do need to do that to make things easy for the user. diff --git a/orderly2.Rproj b/orderly2.Rproj new file mode 100644 index 0000000..497f8bf --- /dev/null +++ b/orderly2.Rproj @@ -0,0 +1,20 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/tests/testthat/helper-orderly.R b/tests/testthat/helper-orderly.R index a68f5d5..e7a00f9 100644 --- a/tests/testthat/helper-orderly.R +++ b/tests/testthat/helper-orderly.R @@ -14,7 +14,8 @@ test_prepare_orderly_example <- function(examples, ...) { config <- c(config, "global_resources: global") fs::dir_create(file.path(tmp, "global")) - fs::file_copy("examples/minimal/data.csv", file.path(tmp, "global")) + fs::file_copy(test_path("examples/minimal/data.csv"), + file.path(tmp, "global")) } if ("plugin" %in% examples) { @@ -29,7 +30,7 @@ test_prepare_orderly_example <- function(examples, ...) { writeLines(config, file.path(tmp, "orderly_config.yml")) fs::dir_create(file.path(tmp, "src")) for (i in examples) { - fs::dir_copy(file.path("examples", i), file.path(tmp, "src")) + fs::dir_copy(test_path("examples", i), file.path(tmp, "src")) } tmp } @@ -54,3 +55,51 @@ json_to_df <- function(x) { hash_file <- function(...) { outpack:::hash_file(...) } + + +test_path <- function(...) { + if (basename(getwd()) == "testthat") { + file.path(...) + } else { + testthat::test_path(...) + } +} + + +## Expects dependencies to be a list of name and id (or search query) +## e.g. +## list(a = "latest", b = "latest(parameter:x == 2)") # nolint +## By convention will expect report artefact to be "data.rds" and will +## map this to "input.rds" in the script.R +create_random_report <- function(root, name = "data", dependencies = NULL) { + report_dir <- fs::dir_create(file.path(root, "src", name)) + withr::defer_parent(unlink(report_dir, recursive = TRUE)) + + yml <- c( + "script: script.R", + "artefacts:", + " data:", + " description: Random data", + " filenames: data.rds" + ) + + if (!is.null(dependencies)) { + assert_named(dependencies) + formatted_depends <- do.call(c, lapply(names(dependencies), function(name) { + id <- dependencies[[name]] + c(sprintf(" - %s:", name), + sprintf(" id: %s", id), + " use:", + " input.rds: data.rds") + })) + yml <- c(yml, "depends:", formatted_depends) + script <- c("x <- readRDS(\"input.rds\")", + "saveRDS(x + runif(10), \"data.rds\")") + } else { + script <- "saveRDS(runif(10), \"data.rds\")" + } + + writeLines(yml, file.path(report_dir, "orderly.yml")) + writeLines(script, file.path(report_dir, "script.R")) + invisible(report_dir) +} diff --git a/tests/testthat/test-run.R b/tests/testthat/test-run.R index 4627c12..c434848 100644 --- a/tests/testthat/test-run.R +++ b/tests/testthat/test-run.R @@ -61,7 +61,7 @@ test_that("Check that required files are produced", { ## TODO: we might add something nice to expose the status of a ## currently running packet. expect_error(outpack::outpack_packet_end(), - "No current packet") + "No currently active packet") ## TODO: Still need something much nicer in outpack for this: root <- orderly_root(path, FALSE) @@ -207,3 +207,23 @@ test_that("can use global resources", { list(list(here = "global_data.csv", there = "data.csv"))) }) + + +test_that("dependencies left in archive do not print extra files message", { + path <- test_prepare_orderly_example(NULL) + create_random_report(path, "a") + create_random_report(path, "b", list(a = "latest")) + + id_a <- orderly_run("a", root = path) + expect_message(id_b <- orderly_run("b", root = path), NULL) + + root <- orderly_root(path, FALSE) + meta <- root$outpack$metadata(id_b, full = TRUE) + expect_equal(meta$depends$packet, id_a) + expect_equal(meta$depends$files[[1]], + data_frame(here = "input.rds", there = "data.rds")) + expect_true(file.exists( + file.path(path, "archive", "b", id_b, "input.rds"))) + expect_true(file.exists( + file.path(path, "archive", "b", id_b, "data.rds"))) +})