Skip to content

Commit a588484

Browse files
authored
Merge pull request #326 from vimc/vimc-7040
add orderly_packages method
2 parents 14f7477 + d17c640 commit a588484

21 files changed

+137
-32
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: orderly
22
Title: Lightweight Reproducible Reporting
3-
Version: 1.5.1
3+
Version: 1.6.0
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
@@ -46,7 +46,7 @@ Suggests:
4646
rmarkdown,
4747
testthat,
4848
vaultr (>= 1.0.4)
49-
RoxygenNote: 7.2.0
49+
RoxygenNote: 7.2.3
5050
Roxygen: list(markdown = TRUE)
5151
VignetteBuilder: knitr
5252
Language: en-GB

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export(orderly_log_off)
3535
export(orderly_log_on)
3636
export(orderly_migrate)
3737
export(orderly_new)
38+
export(orderly_packages)
3839
export(orderly_pull_archive)
3940
export(orderly_pull_dependencies)
4041
export(orderly_push_archive)

R/info.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,21 @@ orderly_info <- function(id, name, root = NULL, locate = TRUE) {
7171
error = error
7272
)
7373
}
74+
75+
##' Return details of packages required by all src reports in this orderly repo
76+
##'
77+
##' @inheritParams orderly_list
78+
##'
79+
##' @return List of packages required by all src reports
80+
##' @export
81+
##'
82+
##' @examples
83+
##' path <- orderly::orderly_example("minimal")
84+
##' orderly::orderly_packages(root = path)
85+
orderly_packages <- function(root = NULL, locate = TRUE) {
86+
cfg <- orderly_config(root, locate)
87+
names <- basename(list_dirs(path_src(cfg$root)))
88+
packages <- lapply(names,
89+
function(name) orderly_recipe$new(name, cfg)$packages)
90+
unique(as.list(unlist(packages)))
91+
}

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ reference:
9999
contents:
100100
- orderly_example
101101
- orderly_run_info
102+
- orderly_packages
102103
- orderly_log
103104
- orderly_log_off
104105
- orderly_log_on

inst/examples/minimal/src/example/orderly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ artefacts:
66
staticgraph:
77
description: A graph of things
88
filenames: mygraph.png
9+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
data:
2+
dat:
3+
query: SELECT name, number FROM thing
4+
script: script.R
5+
artefacts:
6+
staticgraph:
7+
description: A graph of things
8+
filenames: mygraph.png
9+
packages:
10+
- withr
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
png("mygraph.png")
2+
par(mar = c(15, 4, .5, .5))
3+
barplot(setNames(dat$number, dat$name), las = 2)
4+
dev.off()

man/orderly_config.Rd

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/orderly_log.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/orderly_packages.Rd

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/orderly_run.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/orderly_search.Rd

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/examples/packages/orderly_config.yml

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
packages:
2+
- dplyr
3+
- readr
4+
- stringr
5+
script: script.R
6+
artefacts:
7+
staticgraph:
8+
description: A graph of things
9+
filenames: mygraph.png

tests/testthat/examples/packages/src/example/script.R

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
packages: stringr
2+
script: script.R
3+
artefacts:
4+
staticgraph:
5+
description: A graph of things
6+
filenames: mygraph.png

tests/testthat/examples/packages/src/example2/script.R

Whitespace-only changes.

tests/testthat/test-cleanup.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_that("cleanup nothing", {
44
path <- test_prepare_orderly_example("minimal")
55
out <- capture_logs(orderly_cleanup(root = path))
66
expect_null(out$result)
7-
expect_equal(orderly_list(root = path), "example")
7+
expect_equal(orderly_list(root = path), c("example", "example2"))
88
expect_match(out$messages, "Found 0 draft reports", all = FALSE)
99
expect_match(out$messages, "Found 0 csv files", all = FALSE)
1010
expect_match(out$messages, "Found 0 rds files", all = FALSE)

tests/testthat/test-info.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,20 @@ test_that("info errors if fails to find report rds", {
7474
id),
7575
fixed = TRUE)
7676
})
77+
78+
test_that("can retrieve package info", {
79+
path <- test_prepare_orderly_example("packages", testing = TRUE)
80+
packages <- orderly_packages(path)
81+
expect_length(packages, 3)
82+
expect_equal(class(packages), "list")
83+
expect_equal(packages[[1]], "dplyr")
84+
expect_equal(packages[[2]], "readr")
85+
expect_equal(packages[[3]], "stringr")
86+
})
87+
88+
test_that("can retrieve empty package info", {
89+
path <- test_prepare_orderly_example("changelog", testing = TRUE)
90+
packages <- orderly_packages(path)
91+
expect_length(packages, 0)
92+
expect_equal(class(packages), "list")
93+
})

tests/testthat/test-main.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_that("run", {
1515
expect_identical(res$target, main_do_run)
1616

1717
capture.output(res$target(res))
18-
expect_equal(orderly_list(path), "example")
18+
expect_equal(orderly_list(path), c("example", "example2"))
1919
expect_equal(nrow(orderly_list_archive(path)), 1)
2020
})
2121

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

3838
capture.output(res$target(res))
39-
expect_equal(orderly_list(path), "example")
39+
expect_equal(orderly_list(path), c("example", "example2"))
4040

4141
expect_true(file.exists(id_file))
4242
id <- readLines(id_file)
@@ -302,7 +302,7 @@ test_that("list", {
302302
args <- c("--root", path, "list")
303303
res <- cli_args_process(args)
304304

305-
expect_output(res$target(res), "^example$")
305+
expect_output(res$target(res), "^example\\nexample2$")
306306

307307
for (i in c("names", "drafts", "archive")) {
308308
expect_equal(
@@ -420,7 +420,7 @@ test_that("list", {
420420
orderly_commit(id2, root = path)
421421

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

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

699699
capture.output(res$target(res))
700-
expect_equal(orderly_list(path), "example")
700+
expect_equal(orderly_list(path), c("example", "example2"))
701701
expect_equal(nrow(orderly_list_archive(path)), 1)
702702
id <- orderly_list_archive(path)$id
703703
rds <- path_orderly_run_rds(file.path(path, "archive", "example", id))

tests/testthat/test-query.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ test_that("empty", {
1515

1616
test_that("non-empty", {
1717
path <- test_prepare_orderly_example("minimal")
18-
expect_equal(orderly_list(path), "example")
18+
expect_equal(orderly_list(path), c("example", "example2"))
1919
})
2020

2121
test_that("query through lifecycle", {
2222
skip_on_cran_windows()
2323
path <- test_prepare_orderly_example("minimal")
24-
expect_equal(orderly_list(root = path), "example")
24+
expect_equal(orderly_list(root = path), c("example", "example2"))
2525

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

0 commit comments

Comments
 (0)