Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to return details of report script from parsed exprs #129

Merged
merged 8 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export(orderly_metadata_extract)
export(orderly_metadata_read)
export(orderly_new)
export(orderly_parameters)
export(orderly_parse)
export(orderly_plugin_add_metadata)
export(orderly_plugin_context)
export(orderly_plugin_register)
Expand Down
25 changes: 22 additions & 3 deletions R/read.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
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.path(path, entrypoint_filename), entrypoint_filename)
}


orderly_read_r <- function(path, entrypoint_filename) {
exprs <- parse(file = path)
#' Parse the orderly entrypoint script
#'
#' For expert use only.
#'
#' Takes either a path to the orderly entrypoint script or
#' the parsed AST from an orderly script, 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' orderly_ in-script functions are well-formed.
#' `orderly_*` in-script functions are well-formed.

#'
#' @param entrypoint_script Path to script or parsed AST from orderly script
#' @param entrypoint_filename Name of entrypoint file to include in metadata
#'
#' @return Parsed orderly entrypoint script
#' @export
orderly_parse <- function(entrypoint_script, entrypoint_filename) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sold on these argument names (sorry). How about accepting exprs and filename. Probably the input needs checking too (so for entrypoint_filename / filename use assert_file_exists and for entrypoint_script use assert_is(., "expression") I think).

You should also check that exactly one of these is given; this is quite annoying to do; you can use missing() to check that the argument was not given and error if both are !missing() but this makes it hard to program against sometimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially put this in but felt kind of gross when chatting through it with Mantra, I've split this into 2 functions now. How does that look?

if (!is.expression(entrypoint_script)) {
exprs <- parse(file = entrypoint_script)
} else {
exprs <- entrypoint_script
}

inputs <- list()
artefacts <- list()
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ reference:
- orderly_validate_archive
- orderly_hash_data
- orderly_hash_file
- orderly_parse
26 changes: 26 additions & 0 deletions man/orderly_parse.Rd

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

17 changes: 12 additions & 5 deletions tests/testthat/test-read.R
Original file line number Diff line number Diff line change
@@ -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("examples/implicit/implicit.R", "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("examples/explicit/explicit.R", "explicit.R")
expect_setequal(names(dat),
c("entrypoint_filename", "strict", "resources", "artefacts"))
expect_equal(dat$strict, list(enabled = FALSE))
Expand All @@ -17,8 +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(exprs, "explicit.R")
expect_equal(dat, orderly_parse("examples/explicit/explicit.R", "explicit.R"))
})


test_that("Skip over computed resources", {
dat <- orderly_read_r("examples/computed-resource/computed-resource.R",
dat <- orderly_parse("examples/computed-resource/computed-resource.R",
"computed-resource.R")
expect_null(dat$resources)
})
Expand Down
Loading