Skip to content

Commit

Permalink
Sketch fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Apr 13, 2024
1 parent e9a582a commit 2f74005
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
The methodology in this package
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
and 'drake' (2018, <doi:10.21105/joss.00550>).
Version: 1.6.0.9002
Version: 1.6.0.9003
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ S3method(target_get_type_cli,tar_stem)
S3method(target_is_branchable,default)
S3method(target_is_branchable,tar_pattern)
S3method(target_is_branchable,tar_stem)
S3method(target_marshal_value,default)
S3method(target_marshal_value,tar_pattern)
S3method(target_needs_worker,default)
S3method(target_needs_worker,tar_builder)
S3method(target_needs_worker,tar_pattern)
Expand Down Expand Up @@ -277,6 +279,8 @@ S3method(target_skip,tar_pattern)
S3method(target_skip,tar_stem)
S3method(target_sync_file_meta,default)
S3method(target_sync_file_meta,tar_builder)
S3method(target_unmarshal_value,default)
S3method(target_unmarshal_value,tar_pattern)
S3method(target_update_depend,tar_builder)
S3method(target_update_depend,tar_pattern)
S3method(target_validate,tar_branch)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# targets 1.6.0.9002
# targets 1.6.0.9003

## Invalidating changes

* Use `secretbase::siphash13()` instead of `digest(algo = "xxhash64", serializationVersion = 3)` so hashes of in-memory objects no longer depend on serialization version 3 headers (#1244, @shikokuchuo). Unfortunately, pipelines built with earlier versions of `targets` will need to rerun.

## Other improvements

* Ensure patterns marshal properly (#1266, #1264, https://github.com/njtierney/geotargets/issues/52, @Aariq, @njtierney).
* Inform and prompt the user when the pipeline was built with an old version of `targets` and changes to the package will cause the current work to rerun (#1244). For the `tar_make*()` functions, `utils::menu()` prompts the user to give people a chance to downgrade if necessary.
* For type safety in the internal database class, read all columns as character vectors in `data.table::fread()`, then convert them to the correct types afterwards.
* Add a new `tar_resources_custom_format()` function which can pass environment variables to customize the behavior of custom `tar_format()` storage formats (#1263, #1232, @Aariq, @noamross).
Expand Down
10 changes: 10 additions & 0 deletions R/class_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ target_bootstrap.tar_pattern <- function(
invisible()
}

#' @export
target_marshal_value.tar_pattern <- function(target) {
target$value <- NULL
}

#' @export
target_unmarshal_value.tar_pattern <- function(target) {
target$value <- NULL
}

#' @export
print.tar_pattern <- function(x, ...) {
cat(
Expand Down
7 changes: 6 additions & 1 deletion R/class_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ pipeline_marshal_values <- function(pipeline) {
}

pipeline_unmarshal_values <- function(pipeline) {
names <- pipeline_get_names(pipeline)
map(
pipeline_get_names(pipeline),
names,
~target_unmarshal_value(pipeline_get_target(pipeline, .x))
)
map(
names,
~target_ensure_value(pipeline_get_target(pipeline, .x), pipeline)
)
}

pipeline_prune_names <- function(pipeline, names) {
Expand Down
10 changes: 10 additions & 0 deletions R/class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,22 @@ target_sync_file_meta.default <- function(target, meta) {
}

target_marshal_value <- function(target) {
UseMethod("target_marshal_value")
}

#' @export
target_marshal_value.default <- function(target) {
if (!is.null(target$value)) {
store_marshal_value(target$store, target)
}
}

target_unmarshal_value <- function(target) {
UseMethod("target_unmarshal_value")
}

#' @export
target_unmarshal_value.default <- function(target) {
if (!is.null(target$value)) {
store_unmarshal_value(target$store, target)
}
Expand Down
31 changes: 31 additions & 0 deletions tests/testthat/test-tar_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,34 @@ tar_test("custom format envvar resources", {
expect_equal(tar_read(target_name), data.frame(x = 1L))
expect_equal(Sys.getenv("SERIALIZATION", unset = ""), "")
})

tar_test("patterns are marshaled correctly", {
skip_cran()
skip_on_os("windows")
skip_on_os("solaris")
skip_if_not_installed("crew", minimum_version = "0.9.0")
skip_if_not_installed("torch")
on.exit(crew_test_sleep())
tar_script({
tar_option_set(controller = crew::crew_controller_local())
list(
tar_target(x, c(1L, 2L)),
tar_target(
y,
torch::torch_tensor(x),
pattern = map(x),
format = "torch",
iteration = "list"
),
tar_target(
z,
y[[1]] + y[[2]],
format = "torch"
)
)
})
tar_make(callr_function = NULL)
tar_load(z)
expect_s3_class(z, "torch_tensor")
expect_true(identical(as.integer(z), 3L))
})

0 comments on commit 2f74005

Please sign in to comment.