Skip to content

Commit

Permalink
Merge branch 'main' into mrc-4643
Browse files Browse the repository at this point in the history
  • Loading branch information
weshinsley authored Oct 19, 2023
2 parents 670c4c2 + 6c9a04f commit 2dc8962
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
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)

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")))))
})

0 comments on commit 2dc8962

Please sign in to comment.