diff --git a/R/metadata.R b/R/metadata.R index 13536ca0..b2cfc887 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -247,7 +247,9 @@ static_orderly_artefact <- function(args) { ##' @return Undefined ##' @export orderly_dependency <- function(name, query, files) { - assert_scalar_character(name, call = environment()) + if (!is.null(name)) { + assert_scalar_character(name, call = environment()) + } ctx <- orderly_context(rlang::caller_env()) subquery <- NULL @@ -276,6 +278,9 @@ static_orderly_dependency <- function(args) { query <- args$query files <- args$files + static_name <- static_string(name) + has_name <- !is.null(static_name) || is.null(name) + name <- static_string(name) files <- static_character_vector(files, TRUE) @@ -288,10 +293,10 @@ static_orderly_dependency <- function(args) { query <- NULL } - if (is.null(name) || is.null(files) || is.null(query)) { + if (!has_name || is.null(files) || is.null(query)) { return(NULL) } - list(name = name, query = query, files = files) + list(name = static_name, query = query, files = files) } diff --git a/tests/testthat/test-read.R b/tests/testthat/test-read.R index f95393eb..058dff45 100644 --- a/tests/testthat/test-read.R +++ b/tests/testthat/test-read.R @@ -56,6 +56,9 @@ test_that("read dependency", { args <- list(name = "a", query = "latest", files = c(x = "y")) expect_equal(static_orderly_dependency(args), args) + args <- list(name = NULL, query = "latest", files = c(x = "y")) + expect_equal(static_orderly_dependency(args), args) + expect_null( static_orderly_dependency(list(name = quote(a), query = "latest", diff --git a/tests/testthat/test-run.R b/tests/testthat/test-run.R index c7949688..1652037d 100644 --- a/tests/testthat/test-run.R +++ b/tests/testthat/test-run.R @@ -1233,3 +1233,28 @@ test_that("nice error if resource file not found", { expect_match(err$parent$body[[1]], "Looked within directory '.+/src/explicit'") }) + + +test_that("can add a dependency on an id with no name", { + path <- test_prepare_orderly_example(c("data", "depends")) + envir1 <- new.env() + id1 <- orderly_run_quietly("data", root = path, envir = envir1) + + path_src <- file.path(path, "src", "depends", "orderly.R") + code <- readLines(path_src) + i <- grep("orderly2::orderly_dependency", code) + code[[i]] <- sprintf( + "orderly2::orderly_dependency(NULL, '%s', c(input.rds = 'data.rds'))", + id1) + writeLines(code, path_src) + envir2 <- new.env() + id2 <- orderly_run_quietly("depends", root = path, envir = envir2) + + meta <- orderly_metadata(id2, root = path) + expect_equal( + meta$depends, + data_frame( + packet = id1, + query = sprintf('single(id == "%s")', id1), + files = I(list(data_frame(here = "input.rds", there = "data.rds"))))) +})