Skip to content

Commit 2a3c98f

Browse files
committed
Exclude function signatures from tar_format() output strings to reduce the size of pipeline metadata (#1390).
1 parent 29ec725 commit 2a3c98f

11 files changed

+84
-27
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
1212
The methodology in this package
1313
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
1414
and 'drake' (2018, <doi:10.21105/joss.00550>).
15-
Version: 1.9.1.9008
15+
Version: 1.9.1.9009
1616
License: MIT + file LICENSE
1717
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
1818
BugReports: https://github.com/ropensci/targets/issues

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# targets 1.9.1.9008
1+
# targets 1.9.1.9009
22

33
## Invalidating changes
44

55
These changes invalidate certain targets in a pipeline and cause them to rerun on the next `tar_make()`.
66

77
* Exclude function signatures from `tar_repository_cas()` output strings to reduce the size of pipeline metadata (#1390).
8+
* Exclude function signatures from `tar_format()` output strings to reduce the size of pipeline metadata (#1390).
89

910
## Summary of performance gains
1011

R/class_pipeline.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ pipeline_validate <- function(pipeline) {
339339
pipeline_validate_lite <- function(pipeline) {
340340
tar_assert_inherits(pipeline, "tar_pipeline", msg = "invalid pipeline.")
341341
tar_assert_correct_fields(pipeline, pipeline_new)
342+
tar_assert_target_name_case(pipeline_get_names(pipeline))
342343
pipeline_validate_conflicts(pipeline)
343344
}
344345

R/class_store_format_custom.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ store_class_format_format_custom <- c(
99
"tar_store"
1010
)
1111

12-
store_format_custom_field <- function(format, pattern, default) {
12+
store_format_custom_field <- function(format, pattern, default, prefix) {
1313
out <- base64url::base64_urldecode(keyvalue_field(format, pattern))
1414
if ((length(out) < 1L) || !any(nzchar(out))) {
15-
out <- default
15+
return(default)
16+
} else {
17+
return(paste0(prefix, out))
1618
}
17-
out
1819
}
1920

2021
#' @export

R/class_store_format_custom_methods.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,38 @@ store_format_custom_methods_init <- function(format) {
44
read = store_format_custom_field(
55
format = format,
66
pattern = "^read=",
7-
default = store_format_custom_default_read()
7+
default = store_format_custom_default_read(),
8+
prefix = "function(path) "
89
),
910
write = store_format_custom_field(
1011
format = format,
1112
pattern = "^write=",
12-
default = store_format_custom_default_write()
13+
default = store_format_custom_default_write(),
14+
prefix = "function(object, path) "
1315
),
1416
marshal = store_format_custom_field(
1517
format = format,
1618
pattern = "^marshal=",
17-
default = store_format_custom_default_marshal()
19+
default = store_format_custom_default_marshal(),
20+
prefix = "function(object) "
1821
),
1922
unmarshal = store_format_custom_field(
2023
format = format,
2124
pattern = "^unmarshal=",
22-
default = store_format_custom_default_unmarshal()
25+
default = store_format_custom_default_unmarshal(),
26+
prefix = "function(object) "
2327
),
2428
convert = store_format_custom_field(
2529
format = format,
2630
pattern = "^convert=",
27-
default = store_format_custom_default_convert()
31+
default = store_format_custom_default_convert(),
32+
prefix = "function(object) "
2833
),
2934
copy = store_format_custom_field(
3035
format = format,
3136
pattern = "^copy=",
32-
default = store_format_custom_default_copy()
37+
default = store_format_custom_default_copy(),
38+
prefix = "function(object) "
3339
)
3440
)
3541
}

R/tar_format.R

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@
7676
#' See the "Format functions" section for specific requirements.
7777
#' If `NULL`, the `unmarshal` argument defaults to just
7878
#' returning the original object without any modifications.
79-
#' @param convert The `convert` argument is a function
80-
#' that accepts the object returned by the command of the target
79+
#' @param convert The `convert` argument is a function with a single argument
80+
#' named `object`.
81+
#' It accepts the object returned by the command of the target
8182
#' and changes it into an acceptable format (e.g. can be
8283
#' saved with the `read` function). The `convert`
8384
#' ensures the in-memory copy
@@ -88,8 +89,9 @@
8889
#' `error = "null"` in [tar_target()] or [tar_option_set()]).
8990
#' If `NULL`, the `convert` argument defaults to just
9091
#' returning the original object without any modifications.
91-
#' @param copy The `copy` argument is a function
92-
#' that accepts the object returned by the command of the target
92+
#' @param copy The `copy` argument is a function with a single function
93+
#' named `object`.
94+
#' It accepts the object returned by the command of the target
9395
#' and makes a deep copy in memory. This method does is relevant
9496
#' to objects like `data.table`s that support in-place modification
9597
#' which could cause unpredictable side effects from target
@@ -231,10 +233,11 @@ tar_format <- function(
231233
}
232234

233235
tar_format_field <- function(key, value) {
234-
encoded <- if_any(
235-
is.null(value),
236-
"",
237-
base64url::base64_urlencode(tar_deparse_safe(value))
238-
)
239-
paste0(key, "=", encoded)
236+
if (is.null(value)) {
237+
return(paste0(key, "="))
238+
}
239+
if (is.function(value)) {
240+
value <- body(value)
241+
}
242+
paste0(key, "=", base64url::base64_urlencode(tar_deparse_safe(value)))
240243
}

R/tar_target.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,15 @@
198198
#' can refer to this name symbolically to induce a dependency relationship:
199199
#' e.g. `tar_target(downstream_target, f(upstream_target))` is a
200200
#' target named `downstream_target` which depends on a target
201-
#' `upstream_target` and a function `f()`. In addition, a target's
201+
#' `upstream_target` and a function `f()`.
202+
#'
203+
#' In most cases, The target name is the name of its local data file
204+
#' in storage. Some file systems are not case sensitive, which means
205+
#' converting a name to a different case may overwrite a different target.
206+
#' Please ensure all target names have unique names when converted to
207+
#' lower case.
208+
#'
209+
#' In addition, a target's
202210
#' name determines its random number generator seed. In this way,
203211
#' each target runs with a reproducible seed so someone else
204212
#' running the same pipeline should get the same results,

R/utils_assert.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,3 +871,22 @@ tar_assert_meta <- function(store) {
871871
tar_throw_validate(message = message)
872872
}
873873
}
874+
875+
tar_assert_target_name_case <- function(names) {
876+
index <- duplicated(tolower(names))
877+
if (!any(index)) {
878+
return()
879+
}
880+
problems <- paste(names[index], collapse = ", ")
881+
message <- paste0(
882+
"In most pipelines, a target name is the name of its data file in ",
883+
"storage. Some file systems are not case sensitive, so targets ",
884+
"should not have duplicate names when converting to lower case. ",
885+
"Found problematic names: ",
886+
problems
887+
)
888+
tar_warning(
889+
message = message,
890+
class = c("tar_condition_validate", "tar_condition_targets")
891+
)
892+
}

man/tar_format.Rd

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_target.Rd

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-utils_assert.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,11 @@ tar_test("tar_assert_identical()", {
471471
class = "tar_condition_validate"
472472
)
473473
})
474+
475+
tar_test("tar_assert_target_name_case()", {
476+
expect_silent(tar_assert_target_name_case(letters))
477+
expect_warning(
478+
tar_assert_target_name_case(c(letters, LETTERS)),
479+
class = "tar_condition_validate"
480+
)
481+
})

0 commit comments

Comments
 (0)