diff --git a/DESCRIPTION b/DESCRIPTION index 1f862e5ed..e9e512d27 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 @@ -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 diff --git a/NAMESPACE b/NAMESPACE index 2b2a1fc35..f52df00d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/info.R b/R/info.R index 41868bb21..e9cf693fd 100644 --- a/R/info.R +++ b/R/info.R @@ -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))) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 32fb9d732..7ac317863 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -99,6 +99,7 @@ reference: contents: - orderly_example - orderly_run_info + - orderly_packages - orderly_log - orderly_log_off - orderly_log_on diff --git a/inst/examples/minimal/src/example/orderly.yml b/inst/examples/minimal/src/example/orderly.yml index bad1d96e3..a162122b7 100644 --- a/inst/examples/minimal/src/example/orderly.yml +++ b/inst/examples/minimal/src/example/orderly.yml @@ -6,3 +6,4 @@ artefacts: staticgraph: description: A graph of things filenames: mygraph.png + diff --git a/inst/examples/minimal/src/example2/orderly.yml b/inst/examples/minimal/src/example2/orderly.yml new file mode 100644 index 000000000..9b4b3988e --- /dev/null +++ b/inst/examples/minimal/src/example2/orderly.yml @@ -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 diff --git a/inst/examples/minimal/src/example2/script.R b/inst/examples/minimal/src/example2/script.R new file mode 100644 index 000000000..73115a2f3 --- /dev/null +++ b/inst/examples/minimal/src/example2/script.R @@ -0,0 +1,4 @@ +png("mygraph.png") +par(mar = c(15, 4, .5, .5)) +barplot(setNames(dat$number, dat$name), las = 2) +dev.off() diff --git a/man/orderly_config.Rd b/man/orderly_config.Rd index d525817ad..12c4b7f81 100644 --- a/man/orderly_config.Rd +++ b/man/orderly_config.Rd @@ -66,15 +66,15 @@ connection args for (possibly multiple) databases} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{orderly_config_$new()}} -\item \href{#method-server_options}{\code{orderly_config_$server_options()}} -\item \href{#method-add_run_option}{\code{orderly_config_$add_run_option()}} -\item \href{#method-get_run_option}{\code{orderly_config_$get_run_option()}} +\item \href{#method-orderly_config-new}{\code{orderly_config_$new()}} +\item \href{#method-orderly_config-server_options}{\code{orderly_config_$server_options()}} +\item \href{#method-orderly_config-add_run_option}{\code{orderly_config_$add_run_option()}} +\item \href{#method-orderly_config-get_run_option}{\code{orderly_config_$get_run_option()}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-orderly_config-new}{}}} \subsection{Method \code{new()}}{ Create an object representing orderly config \subsection{Usage}{ @@ -94,8 +94,8 @@ for each of the cfg fields} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-server_options}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-orderly_config-server_options}{}}} \subsection{Method \code{server_options()}}{ Get connection options for the current server. This is the details from the "remote" section for the server @@ -111,8 +111,8 @@ otherwise NULL } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-add_run_option}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-orderly_config-add_run_option}{}}} \subsection{Method \code{add_run_option()}}{ Add a key-value pair run option \subsection{Usage}{ @@ -130,8 +130,8 @@ Add a key-value pair run option } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-get_run_option}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-orderly_config-get_run_option}{}}} \subsection{Method \code{get_run_option()}}{ Retrieve value of a run option \subsection{Usage}{ diff --git a/man/orderly_log.Rd b/man/orderly_log.Rd index 693559d16..1777ef935 100644 --- a/man/orderly_log.Rd +++ b/man/orderly_log.Rd @@ -20,10 +20,12 @@ orderly_log(topic, value) \value{ \code{orderly_log_on} and \code{orderly_log_off} invisibly returns a logical indicating if logging was previously enabled. -This allows patterns like:\preformatted{if (!orderly::orderly_log_off()) \{ +This allows patterns like: + +\if{html}{\out{
}}\preformatted{if (!orderly::orderly_log_off()) \{ on.exit(orderly::orderly_log_on()) \} -} +}\if{html}{\out{
}} to disable logging within a function (the \code{on.exit} block will be run when the function exits). diff --git a/man/orderly_packages.Rd b/man/orderly_packages.Rd new file mode 100644 index 000000000..fd6473c39 --- /dev/null +++ b/man/orderly_packages.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/info.R +\name{orderly_packages} +\alias{orderly_packages} +\title{Return details of packages required by all src reports in this orderly repo} +\usage{ +orderly_packages(root = NULL, locate = TRUE) +} +\arguments{ +\item{root}{The path to an orderly root directory, or \code{NULL} +(the default) to search for one from the current working +directory if \code{locate} is \code{TRUE}.} + +\item{locate}{Logical, indicating if the configuration should be +searched for. If \code{TRUE} and \code{config} is not given, +then orderly looks in the working directory and up through its +parents until it finds an \code{orderly_config.yml} file.} +} +\value{ +List of packages required by all src reports +} +\description{ +Return details of packages required by all src reports in this orderly repo +} +\examples{ +path <- orderly::orderly_example("minimal") +orderly::orderly_packages(root = path) +} diff --git a/man/orderly_run.Rd b/man/orderly_run.Rd index 19920bf0b..3e3cd0fa7 100644 --- a/man/orderly_run.Rd +++ b/man/orderly_run.Rd @@ -90,8 +90,10 @@ successfully run you can use \code{\link[=orderly_commit]{orderly_commit()}} to it to the \code{archive} directory. } \details{ -Parameters are passed to the report as a named list, for example\preformatted{id <- orderly::orderly_run("other", list(nmin = 0.2), root = path) -} +Parameters are passed to the report as a named list, for example + +\if{html}{\out{
}}\preformatted{id <- orderly::orderly_run("other", list(nmin = 0.2), root = path) +}\if{html}{\out{
}} (see the examples). The names of the parameters (here, \code{nmin}) must correspond to declared parameters in the diff --git a/man/orderly_search.Rd b/man/orderly_search.Rd index f06ca1e7c..0807f3f8f 100644 --- a/man/orderly_search.Rd +++ b/man/orderly_search.Rd @@ -68,22 +68,26 @@ this query string in a \verb{depends:} section will let you select a report that matches some criteria. For example, suppose that you have report \code{A} that takes a parameter "fruit" with values like "apple", "banana", and a report \code{B} that depends -on A. You could then write:\preformatted{depends: +on A. You could then write: + +\if{html}{\out{
}}\preformatted{depends: A: id: latest(parameter:fruit == "apple") uses: summary.csv: summary.csv -} +}\if{html}{\out{
}} To get the \code{summary.csv} file out of the latest report \code{A} that was run with the "fruit" parameter set to "apple". If "B" itself takes parameters, you can use those parameters in -these query expressions like\preformatted{depends: +these query expressions like + +\if{html}{\out{
}}\preformatted{depends: A: id: latest(parameter:fruit == target_fruit) uses: summary.csv: summary.csv -} +}\if{html}{\out{
}} (assuming that \code{B} takes a parameter \code{target_fruit}). @@ -92,8 +96,10 @@ test for presence of a tag called "tagname". Search queries can be joined by \code{&&} and \code{||} and grouped using parentheses, these groups (or tags) can be negated -with \code{!}, so a complicated query expression might look like:\preformatted{(parameter:fruit == "apple" && !tag:weekly) || parameter:fruit == "banana" -} +with \code{!}, so a complicated query expression might look like: + +\if{html}{\out{
}}\preformatted{(parameter:fruit == "apple" && !tag:weekly) || parameter:fruit == "banana" +}\if{html}{\out{
}} Be careful of comparing floating point numbers with \code{==} or \code{!=} as they may not always return what you expect (for example diff --git a/tests/testthat/examples/packages/orderly_config.yml b/tests/testthat/examples/packages/orderly_config.yml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/testthat/examples/packages/src/example/orderly.yml b/tests/testthat/examples/packages/src/example/orderly.yml new file mode 100644 index 000000000..1f3efde4d --- /dev/null +++ b/tests/testthat/examples/packages/src/example/orderly.yml @@ -0,0 +1,9 @@ +packages: + - dplyr + - readr + - stringr +script: script.R +artefacts: + staticgraph: + description: A graph of things + filenames: mygraph.png diff --git a/tests/testthat/examples/packages/src/example/script.R b/tests/testthat/examples/packages/src/example/script.R new file mode 100644 index 000000000..e69de29bb diff --git a/tests/testthat/examples/packages/src/example2/orderly.yml b/tests/testthat/examples/packages/src/example2/orderly.yml new file mode 100644 index 000000000..aa060eb2f --- /dev/null +++ b/tests/testthat/examples/packages/src/example2/orderly.yml @@ -0,0 +1,6 @@ +packages: stringr +script: script.R +artefacts: + staticgraph: + description: A graph of things + filenames: mygraph.png diff --git a/tests/testthat/examples/packages/src/example2/script.R b/tests/testthat/examples/packages/src/example2/script.R new file mode 100644 index 000000000..e69de29bb diff --git a/tests/testthat/test-cleanup.R b/tests/testthat/test-cleanup.R index 643c8536c..a6724ad41 100644 --- a/tests/testthat/test-cleanup.R +++ b/tests/testthat/test-cleanup.R @@ -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) diff --git a/tests/testthat/test-info.R b/tests/testthat/test-info.R index 193135c01..c2437ef83 100644 --- a/tests/testthat/test-info.R +++ b/tests/testthat/test-info.R @@ -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") +}) diff --git a/tests/testthat/test-main.R b/tests/testthat/test-main.R index df37957d2..5e6b6a449 100644 --- a/tests/testthat/test-main.R +++ b/tests/testthat/test-main.R @@ -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) }) @@ -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) @@ -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( @@ -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)) @@ -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)) diff --git a/tests/testthat/test-query.R b/tests/testthat/test-query.R index ecc7051d9..09cb50f02 100644 --- a/tests/testthat/test-query.R +++ b/tests/testthat/test-query.R @@ -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)