Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of NULL for name in dependency #113

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orderly2
Title: Orderly Next Generation
Version: 1.99.6
Version: 1.99.7
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
11 changes: 8 additions & 3 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be ! before is.null(name) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, here it means that "the name we have is final"


name <- static_string(name)
files <- static_character_vector(files, TRUE)

Expand All @@ -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)
}


Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-run.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")))))
})