-
Help
DescriptionThank you for the wonderful targets package. What is the expected behavior of
The documentation and #1263 (comment) suggest that the environment vars are available in library(targets)
tar_script({
tar_target(
a, data.frame(alpha = letters),
resources = tar_resources(custom = tar_resources_custom_format(c(foo = "bar"))),
format = tar_format(
read = function(path) {
res <- readRDS(path)
attr(res, "read_has_foo") <- "foo" %in% names(Sys.getenv())
res
},
write = function(object, path) {
attr(object, "write_has_foo") <- "foo" %in% names(Sys.getenv())
saveRDS(object, path)
}
)
)
})
tar_make()
#> + a dispatched
#> ✔ a completed [0ms, 198 B]
#> ✔ ended pipeline [77ms, 1 completed, 0 skipped]
tar_load(a)
attributes(a)
#> $names
#> [1] "alpha"
#>
#> $class
#> [1] "data.frame"
#>
#> $row.names
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26
#>
#> $write_has_foo
#> [1] TRUE
#>
#> $read_has_foo
#> [1] FALSE |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
That's a tricky one. Those envvars are available during tar_option_set(resources = tar_resources(
custom = tar_resources_custom_format(c(foo = "bar"))
))
object <- tar_read(a)
attr(object, "write_has_foo")
#> [1] TRUE
attr(object, "read_has_foo")
#> [1] TRUE |
Beta Was this translation helpful? Give feedback.
That's a tricky one. Those envvars are available during
tar_make()for both read and write, but not necessarily fortar_read()outside a pipeline. Since environment variables could contain secrets like security credentials,targetsdoes not save them. So you'll have to manually set the resources in the interactive R session where you want to runtar_read().