diff --git a/DESCRIPTION b/DESCRIPTION index f31a2101..131cf5a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: orderly2 Title: Orderly Next Generation -Version: 1.99.12 +Version: 1.99.13 Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), email = "rich.fitzjohn@gmail.com"), person("Robert", "Ashton", role = "aut"), @@ -11,7 +11,7 @@ Description: Reimplementation of orderly based on outpack. License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 URL: https://github.com/mrc-ide/orderly2 BugReports: https://github.com/mrc-ide/orderly2/issues Imports: diff --git a/NAMESPACE b/NAMESPACE index 1b22cabf..4c96b240 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,8 @@ export(orderly_metadata_extract) export(orderly_metadata_read) export(orderly_new) export(orderly_parameters) +export(orderly_parse_expr) +export(orderly_parse_file) export(orderly_plugin_add_metadata) export(orderly_plugin_context) export(orderly_plugin_register) diff --git a/R/read.R b/R/read.R index 3faa6edf..e16da060 100644 --- a/R/read.R +++ b/R/read.R @@ -1,11 +1,35 @@ orderly_read <- function(path, call = NULL) { entrypoint_filename <- find_entrypoint_filename(path) - orderly_read_r(file.path(path, entrypoint_filename), entrypoint_filename) + orderly_parse_file(file.path(path, entrypoint_filename)) } -orderly_read_r <- function(path, entrypoint_filename) { +#' Parse the orderly entrypoint script +#' +#' For expert use only. +#' +#' Parses details of any calls to the orderly_ in-script functions +#' into intermediate representation for downstream use. Also validates +#' that any calls to `orderly_*` in-script functions are well-formed. +#' +#' @param path Path to `orderly_*` script +#' +#' @return Parsed orderly entrypoint script +#' @export +orderly_parse_file <- function(path) { + assert_file_exists(path) exprs <- parse(file = path) + orderly_parse_expr(exprs, basename(path)) +} + + +#' @param exprs Parsed AST from `orderly_*` script +#' @param filename Name of `orderly_*` file to include in metadata +#' +#' @rdname orderly_parse_file +#' @export +orderly_parse_expr <- function(exprs, filename) { + assert_is(exprs, "expression") inputs <- list() artefacts <- list() @@ -50,7 +74,7 @@ orderly_read_r <- function(path, entrypoint_filename) { ## Rename to make things easier below: names(dat) <- sub("^orderly_", "", names(dat)) - ret <- list(entrypoint_filename = entrypoint_filename) + ret <- list(entrypoint_filename = filename) if (length(dat$strict_mode) > 0) { ret$strict <- dat$strict_mode[[1]] } else { @@ -76,7 +100,7 @@ orderly_read_r <- function(path, entrypoint_filename) { if (length(dat$resource) > 0) { ret$resources <- setdiff(unique(unlist(dat$resource, TRUE, FALSE)), - entrypoint_filename) + filename) } if (length(dat$artefact) > 0) { ret$artefacts <- dat$artefact diff --git a/_pkgdown.yml b/_pkgdown.yml index 4a9ead98..72bbe997 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -86,3 +86,5 @@ reference: - orderly_validate_archive - orderly_hash_data - orderly_hash_file + - orderly_parse_file + - orderly_parse_expr diff --git a/man/orderly_parse_file.Rd b/man/orderly_parse_file.Rd new file mode 100644 index 00000000..e15f05cb --- /dev/null +++ b/man/orderly_parse_file.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read.R +\name{orderly_parse_file} +\alias{orderly_parse_file} +\alias{orderly_parse_expr} +\title{Parse the orderly entrypoint script} +\usage{ +orderly_parse_file(path) + +orderly_parse_expr(exprs, filename) +} +\arguments{ +\item{path}{Path to \verb{orderly_*} script} + +\item{exprs}{Parsed AST from \verb{orderly_*} script} + +\item{filename}{Name of \verb{orderly_*} file to include in metadata} +} +\value{ +Parsed orderly entrypoint script +} +\description{ +For expert use only. +} +\details{ +Parses details of any calls to the orderly_ in-script functions +into intermediate representation for downstream use. Also validates +that any calls to \verb{orderly_*} in-script functions are well-formed. +} diff --git a/tests/testthat/test-read.R b/tests/testthat/test-read.R index 77f9c480..8f0ec350 100644 --- a/tests/testthat/test-read.R +++ b/tests/testthat/test-read.R @@ -1,12 +1,12 @@ -test_that("can read file with no helpers", { - expect_equal(orderly_read_r("examples/implicit/implicit.R", "implicit.R"), +test_that("can parse file with no helpers", { + expect_equal(orderly_parse_file("examples/implicit/implicit.R"), list(entrypoint_filename = "implicit.R", strict = list(enabled = FALSE))) }) -test_that("can read file with helpers", { - dat <- orderly_read_r("examples/explicit/explicit.R", "explicit.R") +test_that("can parse file with helpers", { + dat <- orderly_parse_file("examples/explicit/explicit.R") expect_setequal(names(dat), c("entrypoint_filename", "strict", "resources", "artefacts")) expect_equal(dat$strict, list(enabled = FALSE)) @@ -17,9 +17,15 @@ test_that("can read file with helpers", { }) +test_that("can parse file from expression", { + exprs <- parse(file = "examples/explicit/explicit.R") + dat <- orderly_parse_expr(exprs = exprs, filename = "explicit.R") + expect_equal(dat, orderly_parse_file("examples/explicit/explicit.R")) +}) + + test_that("Skip over computed resources", { - dat <- orderly_read_r("examples/computed-resource/computed-resource.R", - "computed-resource.R") + dat <- orderly_parse_file("examples/computed-resource/computed-resource.R") expect_null(dat$resources) })