Skip to content

Commit

Permalink
Merge pull request #326 from vimc/vimc-7040
Browse files Browse the repository at this point in the history
add orderly_packages method
  • Loading branch information
richfitz authored Apr 19, 2023
2 parents 14f7477 + d17c640 commit a588484
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 32 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orderly
Title: Lightweight Reproducible Reporting
Version: 1.5.1
Version: 1.6.0
Description: Order, create and store reports from R. By defining a
lightweight interface around the inputs and outputs of an
analysis, a lot of the repetitive work for reproducible research
Expand Down Expand Up @@ -46,7 +46,7 @@ Suggests:
rmarkdown,
testthat,
vaultr (>= 1.0.4)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Language: en-GB
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export(orderly_log_off)
export(orderly_log_on)
export(orderly_migrate)
export(orderly_new)
export(orderly_packages)
export(orderly_pull_archive)
export(orderly_pull_dependencies)
export(orderly_push_archive)
Expand Down
18 changes: 18 additions & 0 deletions R/info.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,21 @@ orderly_info <- function(id, name, root = NULL, locate = TRUE) {
error = error
)
}

##' Return details of packages required by all src reports in this orderly repo
##'
##' @inheritParams orderly_list
##'
##' @return List of packages required by all src reports
##' @export
##'
##' @examples
##' path <- orderly::orderly_example("minimal")
##' orderly::orderly_packages(root = path)
orderly_packages <- function(root = NULL, locate = TRUE) {
cfg <- orderly_config(root, locate)
names <- basename(list_dirs(path_src(cfg$root)))
packages <- lapply(names,
function(name) orderly_recipe$new(name, cfg)$packages)
unique(as.list(unlist(packages)))
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ reference:
contents:
- orderly_example
- orderly_run_info
- orderly_packages
- orderly_log
- orderly_log_off
- orderly_log_on
Expand Down
1 change: 1 addition & 0 deletions inst/examples/minimal/src/example/orderly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ artefacts:
staticgraph:
description: A graph of things
filenames: mygraph.png

10 changes: 10 additions & 0 deletions inst/examples/minimal/src/example2/orderly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data:
dat:
query: SELECT name, number FROM thing
script: script.R
artefacts:
staticgraph:
description: A graph of things
filenames: mygraph.png
packages:
- withr
4 changes: 4 additions & 0 deletions inst/examples/minimal/src/example2/script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
png("mygraph.png")
par(mar = c(15, 4, .5, .5))
barplot(setNames(dat$number, dat$name), las = 2)
dev.off()
24 changes: 12 additions & 12 deletions man/orderly_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/orderly_log.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/orderly_packages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/orderly_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions man/orderly_search.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
9 changes: 9 additions & 0 deletions tests/testthat/examples/packages/src/example/orderly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
packages:
- dplyr
- readr
- stringr
script: script.R
artefacts:
staticgraph:
description: A graph of things
filenames: mygraph.png
Empty file.
6 changes: 6 additions & 0 deletions tests/testthat/examples/packages/src/example2/orderly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
packages: stringr
script: script.R
artefacts:
staticgraph:
description: A graph of things
filenames: mygraph.png
Empty file.
2 changes: 1 addition & 1 deletion tests/testthat/test-cleanup.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("cleanup nothing", {
path <- test_prepare_orderly_example("minimal")
out <- capture_logs(orderly_cleanup(root = path))
expect_null(out$result)
expect_equal(orderly_list(root = path), "example")
expect_equal(orderly_list(root = path), c("example", "example2"))
expect_match(out$messages, "Found 0 draft reports", all = FALSE)
expect_match(out$messages, "Found 0 csv files", all = FALSE)
expect_match(out$messages, "Found 0 rds files", all = FALSE)
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,20 @@ test_that("info errors if fails to find report rds", {
id),
fixed = TRUE)
})

test_that("can retrieve package info", {
path <- test_prepare_orderly_example("packages", testing = TRUE)
packages <- orderly_packages(path)
expect_length(packages, 3)
expect_equal(class(packages), "list")
expect_equal(packages[[1]], "dplyr")
expect_equal(packages[[2]], "readr")
expect_equal(packages[[3]], "stringr")
})

test_that("can retrieve empty package info", {
path <- test_prepare_orderly_example("changelog", testing = TRUE)
packages <- orderly_packages(path)
expect_length(packages, 0)
expect_equal(class(packages), "list")
})
10 changes: 5 additions & 5 deletions tests/testthat/test-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_that("run", {
expect_identical(res$target, main_do_run)

capture.output(res$target(res))
expect_equal(orderly_list(path), "example")
expect_equal(orderly_list(path), c("example", "example2"))
expect_equal(nrow(orderly_list_archive(path)), 1)
})

Expand All @@ -36,7 +36,7 @@ test_that("run: id-file", {
expect_identical(res$target, main_do_run)

capture.output(res$target(res))
expect_equal(orderly_list(path), "example")
expect_equal(orderly_list(path), c("example", "example2"))

expect_true(file.exists(id_file))
id <- readLines(id_file)
Expand Down Expand Up @@ -302,7 +302,7 @@ test_that("list", {
args <- c("--root", path, "list")
res <- cli_args_process(args)

expect_output(res$target(res), "^example$")
expect_output(res$target(res), "^example\\nexample2$")

for (i in c("names", "drafts", "archive")) {
expect_equal(
Expand Down Expand Up @@ -420,7 +420,7 @@ test_that("list", {
orderly_commit(id2, root = path)

res <- cli_args_process(c("--root", path, "list", "names"))
expect_equal(capture.output(res$target(res)), "example")
expect_equal(capture.output(res$target(res)), c("example", "example2"))

res <- cli_args_process(c("--root", path, "list", "drafts"))
out1 <- capture.output(res$target(res))
Expand Down Expand Up @@ -697,7 +697,7 @@ test_that("run can save workflow metadata", {
expect_equal(res$options$workflow_id, "123")

capture.output(res$target(res))
expect_equal(orderly_list(path), "example")
expect_equal(orderly_list(path), c("example", "example2"))
expect_equal(nrow(orderly_list_archive(path)), 1)
id <- orderly_list_archive(path)$id
rds <- path_orderly_run_rds(file.path(path, "archive", "example", id))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-query.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ test_that("empty", {

test_that("non-empty", {
path <- test_prepare_orderly_example("minimal")
expect_equal(orderly_list(path), "example")
expect_equal(orderly_list(path), c("example", "example2"))
})

test_that("query through lifecycle", {
skip_on_cran_windows()
path <- test_prepare_orderly_example("minimal")
expect_equal(orderly_list(root = path), "example")
expect_equal(orderly_list(root = path), c("example", "example2"))

empty <- data.frame(name = character(0), id = character(0),
stringsAsFactors = FALSE)
Expand Down

0 comments on commit a588484

Please sign in to comment.