-
Notifications
You must be signed in to change notification settings - Fork 2
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
Basic support for dependencies #5
Changes from all commits
dbd1e43
3dce250
e4c5c33
4e10f9b
7391cf8
16f38cf
155e3c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ Imports: | |
fs, | ||
jsonlite, | ||
orderly, | ||
outpack, | ||
outpack (>= 0.2.4), | ||
withr, | ||
yaml | ||
Suggests: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(orderly_artefact) | ||
export(orderly_depends) | ||
export(orderly_parameters) | ||
export(orderly_resource) | ||
export(orderly_run) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## This is something that we might improve over time - it will likely | ||
## be useful to have some sort of "register interactive" function | ||
## which we could then just look up. | ||
## | ||
## I am not sure if we also want to allow working interactively from a | ||
## draft directory too. | ||
detect_orderly_interactive_path <- function(path = getwd()) { | ||
path_split <- fs::path_split(path)[[1]] | ||
is_plausible <- length(path_split) > 2 && | ||
path_split[[length(path_split) - 1]] == "src" && | ||
file.exists(file.path(path, "../..", "orderly_config.yml")) | ||
if (!is_plausible) { | ||
stop(sprintf("Failed to detect orderly path at '%s'", path)) | ||
} | ||
orderly_root(file.path(path, "../.."), FALSE) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,79 @@ static_orderly_artefact <- function(args) { | |
} | ||
|
||
|
||
##' Declare a dependency on another packet | ||
##' | ||
##' @title Declare a dependency | ||
##' | ||
##' @param name The name of the packet to depend on | ||
##' | ||
##' @param query The query to search for; often this will simply be | ||
##' the string `latest`, indicating the most recent version. You may | ||
##' want a more complex query here though. | ||
##' | ||
##' @param use A named character vector of filenames to copy from the | ||
##' upstream packet. The name corresponds to the destination name, | ||
##' so c(here.csv = "there.csv") will take the upstream file | ||
##' `there.csv` and copy it over as `here.csv`. | ||
##' | ||
##' @return Undefined | ||
##' @export | ||
orderly_depends <- function(name, query, use) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like it would be nice if you could just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but here's the pair of issues issue with that: First, In the case where you want to compute the filenames passing in dots is hard as R does not have a spread/splat operator. This will be an issue for Pete's case where we are pulling in things from different regions and renaming them as what we can do with an explicit for (r in regions) {
query <- rlang::expr(parameter:region == !!r)
use <- setNames("data.rds", file.path("data", paste0(r, ".rds")))
orderly_depends("data", query, use)
} Second, you can compromise by adding a get collisions with names, so we could write:
or by carefully processing I had a look at sorting this out but it looks complicated enough that I'd rather kick it down the road a bit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
assert_scalar_character(name) | ||
assert_scalar_character(query) | ||
|
||
assert_character(use) | ||
assert_named(use, unique = TRUE) | ||
|
||
p <- get_active_packet() | ||
if (is.null(p)) { | ||
path <- getwd() | ||
root <- detect_orderly_interactive_path(path) | ||
env <- parent.frame() | ||
id <- outpack::outpack_query(query, env, name = name, | ||
require_unpacked = TRUE, | ||
root = root$outpack) | ||
outpack::outpack_copy_files(id, use, path, root$outpack) | ||
} else { | ||
id <- outpack::outpack_query(query, p$parameters, name = name, | ||
require_unpacked = TRUE, | ||
root = p$root) | ||
outpack::outpack_packet_use_dependency(id, use, p) | ||
} | ||
|
||
invisible() | ||
} | ||
|
||
|
||
static_orderly_depends <- function(args) { | ||
name <- args$name | ||
query <- args$query | ||
use <- args$use | ||
|
||
name <- static_string(name) | ||
use <- static_character_vector(use) | ||
## TODO: allow passing expressions directly in, that will be much | ||
## nicer, but possibly needs some care as we do want a consistent | ||
## approach to NSE here | ||
query <- static_string(query) | ||
if (is.null(name) || is.null(use) || is.null(query)) { | ||
return(NULL) | ||
} | ||
list(name = name, query = query, use = use) | ||
} | ||
|
||
|
||
static_string <- function(x) { | ||
if (is.character(x)) { | ||
x | ||
} else if (is_call(x, "c") && length(x) == 2 && is.character(x[[2]])) { | ||
x[[2]] | ||
} else { | ||
NULL | ||
} | ||
} | ||
|
||
|
||
static_character_vector <- function(x) { | ||
if (is.character(x)) { | ||
x | ||
|
@@ -133,6 +206,7 @@ static_character_vector <- function(x) { | |
} | ||
|
||
|
||
|
||
static_eval <- function(fn, call) { | ||
if (is_call(call[[1]], "::")) { | ||
call[[1]] <- call[[1]][[3]] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
orderly3::orderly_depends("explicit", "latest", c(graph.png = "mygraph.png")) | ||
orderly3::orderly_artefact("Final plot", "graph.png") | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test case where the name of the dependency is different from the artefact? Ran into an issue with this in orderly2 which is what vimc/orderly2#8 is addressing. Could also do that in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this example the dependency is being renamed, but there's no "unexpected files" check yet here (it'll be a bit harder to add). Or is it something else that's missing in the orderly2 test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean the name of the dependency after being pulled into this report run is different from the name of the artefact. They are the same here as you say. Though actually if we have no unexpected files check here then comment above is not relevant! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test_that("can detect orderly directory", { | ||
path <- test_prepare_orderly_example("explicit") | ||
env <- new.env() | ||
id <- orderly_run("explicit", root = path, envir = env) | ||
|
||
expect_error( | ||
detect_orderly_interactive_path(path), | ||
"Failed to detect orderly path at") | ||
expect_error( | ||
detect_orderly_interactive_path(file.path(path, "src")), | ||
"Failed to detect orderly path at") | ||
root <- detect_orderly_interactive_path(file.path(path, "src", "explicit")) | ||
expect_s3_class(root, "orderly_root") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the most consistent with the other function names would be
orderly_dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in #9