Skip to content

Commit 14f7477

Browse files
authored
Merge pull request #323 from vimc/vimc-6820
Better handling of empty queries
2 parents 4100743 + 7c04be5 commit 14f7477

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: orderly
22
Title: Lightweight Reproducible Reporting
3-
Version: 1.5.0
3+
Version: 1.5.1
44
Description: Order, create and store reports from R. By defining a
55
lightweight interface around the inputs and outputs of an
66
analysis, a lot of the repetitive work for reproducible research

R/query_search.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,26 @@ parse_query <- function(x, parameters) {
229229
}
230230
expr <- expr[[1L]]
231231

232-
latest <- is_call(expr, "latest")
232+
test <- c("parameter", "tag")
233+
234+
latest <- is_call(expr, "latest") || identical(expr, as.name("latest"))
233235
if (latest) {
234-
stopifnot(length(expr) == 2L)
235-
expr <- expr[[2L]]
236+
if (length(expr) == 1L) {
237+
## Special exit to make latest() work; this is done better in
238+
## outpack.
239+
return(list(latest = TRUE,
240+
use = set_names(as.list(rep(FALSE, length(test))), test),
241+
expr = TRUE))
242+
} else if (length(expr) == 2L) {
243+
expr <- expr[[2L]]
244+
} else {
245+
stop(sprintf(
246+
"Unexpected query '%s'; expected at most one argument to latest", x))
247+
}
236248
}
237249

238250
dat <- parse_query_expr(expr, parameters)
239251

240-
test <- c("parameter", "tag")
241252
use <- set_names(as.list(test %in% dat$namespace), test)
242253
expr <- dat$expr
243254
list(latest = latest, use = use, expr = expr)

tests/testthat/test-query-search.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,23 @@ test_that("run query on remote", {
436436
draft = "newer", remote = remote, root = root),
437437
"Can't use 'draft' along with 'remote'")
438438
})
439+
440+
441+
test_that("can cope with empty latest", {
442+
dat <- prepare_orderly_query_example()
443+
root <- dat$root
444+
ids <- dat$ids
445+
expect_equal(orderly_search("latest", "other", root = root), last(ids))
446+
expect_equal(orderly_search("latest()", "other", root = root), last(ids))
447+
})
448+
449+
450+
test_that("meaningful error on multi-arg latest", {
451+
dat <- prepare_orderly_query_example()
452+
root <- dat$root
453+
ids <- dat$ids
454+
expect_error(
455+
orderly_search("latest(a, b)", "other", root = root),
456+
"Unexpected query 'latest(a, b)'; expected at most one argument to latest",
457+
fixed = TRUE)
458+
})

0 commit comments

Comments
 (0)