From 8ab2305d7d1c0a212549970f613fd84916e64278 Mon Sep 17 00:00:00 2001 From: wlandau Date: Tue, 9 Apr 2024 15:54:46 -0400 Subject: [PATCH] tar_resources_custom_format() --- DESCRIPTION | 2 +- NAMESPACE | 3 + NEWS.md | 3 +- R/class_resources_custom_format.R | 31 +++++++ R/class_store_custom.R | 15 +++- R/tar_resources.R | 7 +- R/tar_resources_custom_format.R | 44 +++++++++ man/tar_resources.Rd | 9 +- man/tar_resources_aws.Rd | 1 + man/tar_resources_clustermq.Rd | 1 + man/tar_resources_crew.Rd | 1 + man/tar_resources_custom_format.Rd | 89 +++++++++++++++++++ man/tar_resources_feather.Rd | 1 + man/tar_resources_fst.Rd | 1 + man/tar_resources_future.Rd | 1 + man/tar_resources_gcp.Rd | 1 + man/tar_resources_network.Rd | 1 + man/tar_resources_parquet.Rd | 1 + man/tar_resources_qs.Rd | 1 + man/tar_resources_url.Rd | 1 + .../test-class_resources_custom_format.R | 10 +++ tests/testthat/test-tar_format.R | 26 ++++++ .../test-tar_resources_custom_format.R | 26 ++++++ 23 files changed, 269 insertions(+), 7 deletions(-) create mode 100644 R/class_resources_custom_format.R create mode 100644 R/tar_resources_custom_format.R create mode 100644 man/tar_resources_custom_format.Rd create mode 100644 tests/testthat/test-class_resources_custom_format.R create mode 100644 tests/testthat/test-tar_resources_custom_format.R diff --git a/DESCRIPTION b/DESCRIPTION index 3a918a1c4..06fdfd9c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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, ). -Version: 1.6.0.9001 +Version: 1.6.0.9002 License: MIT + file LICENSE URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets BugReports: https://github.com/ropensci/targets/issues diff --git a/NAMESPACE b/NAMESPACE index 1f484dff5..b9dea9a1e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ S3method(print,tar_pipeline) S3method(print,tar_resources_aws) S3method(print,tar_resources_clustermq) S3method(print,tar_resources_crew) +S3method(print,tar_resources_custom_format) S3method(print,tar_resources_feather) S3method(print,tar_resources_fst) S3method(print,tar_resources_future) @@ -28,6 +29,7 @@ S3method(resources_validate,default) S3method(resources_validate,tar_resources_aws) S3method(resources_validate,tar_resources_clustermq) S3method(resources_validate,tar_resources_crew) +S3method(resources_validate,tar_resources_custom_format) S3method(resources_validate,tar_resources_feather) S3method(resources_validate,tar_resources_fst) S3method(resources_validate,tar_resources_future) @@ -466,6 +468,7 @@ export(tar_resources) export(tar_resources_aws) export(tar_resources_clustermq) export(tar_resources_crew) +export(tar_resources_custom_format) export(tar_resources_feather) export(tar_resources_fst) export(tar_resources_future) diff --git a/NEWS.md b/NEWS.md index 1b49f5702..dd1e12c81 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# targets 1.6.0.9001 +# targets 1.6.0.9002 ## Invalidating changes @@ -8,6 +8,7 @@ * 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). # targets 1.6.0 diff --git a/R/class_resources_custom_format.R b/R/class_resources_custom_format.R new file mode 100644 index 000000000..60d33ac1c --- /dev/null +++ b/R/class_resources_custom_format.R @@ -0,0 +1,31 @@ +resources_custom_format_init <- function( + envvars = NULL +) { + resources_custom_format_new( + envvars = envvars + ) +} + +resources_custom_format_new <- function( + envvars = NULL +) { + force(envvars) + enclass(environment(), c("tar_resources_custom_format", "tar_resources")) +} + +#' @export +resources_validate.tar_resources_custom_format <- function(resources) { + if (!is.null(resources$envvars)) { + tar_assert_chr(resources$envvars) + tar_assert_none_na(resources$envvars) + tar_assert_named(resources$controller) + } +} + +#' @export +print.tar_resources_custom_format <- function(x, ...) { + cat( + "\n ", + paste0(paste_list(as.list(x)), collapse = "\n ") + ) +} diff --git a/R/class_store_custom.R b/R/class_store_custom.R index 2e0408dd0..ac78c1371 100644 --- a/R/class_store_custom.R +++ b/R/class_store_custom.R @@ -81,6 +81,7 @@ store_assert_format_setting.format_custom <- function(format) { #' @export store_read_path.tar_store_custom <- function(store, path) { store_custom_call_method( + store = store, text = store$read, args = list(path = path) ) @@ -89,6 +90,7 @@ store_read_path.tar_store_custom <- function(store, path) { #' @export store_write_path.tar_store_custom <- function(store, object, path) { store_custom_call_method( + store = store, text = store$write, args = list(object = object, path = path) ) @@ -97,6 +99,7 @@ store_write_path.tar_store_custom <- function(store, object, path) { #' @export store_marshal_object.tar_store_custom <- function(store, object) { store_custom_call_method( + store = store, text = store$marshal, args = list(object = object) ) @@ -105,6 +108,7 @@ store_marshal_object.tar_store_custom <- function(store, object) { #' @export store_unmarshal_object.tar_store_custom <- function(store, object) { store_custom_call_method( + store = store, text = store$unmarshal, args = list(object = object) ) @@ -113,6 +117,7 @@ store_unmarshal_object.tar_store_custom <- function(store, object) { #' @export store_convert_object.tar_store_custom <- function(store, object) { store_custom_call_method( + store = store, text = store$convert, args = list(object = object) ) @@ -121,12 +126,20 @@ store_convert_object.tar_store_custom <- function(store, object) { #' @export store_copy_object.tar_store_custom <- function(store, object) { store_custom_call_method( + store = store, text = store$copy, args = list(object = object) ) } -store_custom_call_method <- function(text, args) { +store_custom_call_method <- function(store, text, args) { + envvars <- store$resources$custom_format$envvars + if (length(envvars)) { + names <- names(envvars) + previous <- Sys.getenv(names, names = TRUE) + on.exit(do.call(what = Sys.setenv, args = as.list(previous))) + do.call(what = Sys.setenv, args = as.list(envvars)) + } envir <- new.env(parent = baseenv()) what <- eval(parse(text = text), envir = envir) do.call(what = what, args = args, envir = envir) diff --git a/R/tar_resources.R b/R/tar_resources.R index 1e3b6723b..64046b544 100644 --- a/R/tar_resources.R +++ b/R/tar_resources.R @@ -41,14 +41,16 @@ #' So the correct way to assign `clustermq` resources is through #' [tar_option_set()], not [tar_target()]. `clustermq` resources #' in individual [tar_target()] calls will be ignored. -#' @param crew Output of function `tar_resources_crew()` +#' @param crew Output of function [tar_resources_crew()] #' with target-specific settings for integration with the #' `crew` R package. These settings are arguments to the `push()` #' method of the controller or controller group #' object which control things like #' auto-scaling behavior and the controller to use in the case #' of a controller group. -#' @param feather Output of function `tar_resources_feather()`. +#' @param custom_format Output of function [tar_resources_custom_format()] +#' with configuration details for [tar_format()] storage formats. +#' @param feather Output of function [tar_resources_feather()]. #' Non-default arguments to `arrow::read_feather()` and #' `arrow::write_feather()` for `arrow`/feather-based storage formats. #' Applies to all formats ending with the `"_feather"` suffix. @@ -113,6 +115,7 @@ tar_resources <- function( aws = tar_option_get("resources")$aws, clustermq = tar_option_get("resources")$clustermq, crew = tar_option_get("resources")$crew, + custom_format = tar_option_get("resources")$custom_format, feather = tar_option_get("resources")$feather, fst = tar_option_get("resources")$fst, future = tar_option_get("resources")$future, diff --git a/R/tar_resources_custom_format.R b/R/tar_resources_custom_format.R new file mode 100644 index 000000000..b179ccddc --- /dev/null +++ b/R/tar_resources_custom_format.R @@ -0,0 +1,44 @@ +#' @title Target resources for custom storage formats +#' @export +#' @family resources +#' @description Create the `custom_format` argument of `tar_resources()` +#' to specify optional target settings for custom storage formats. +#' @details `tar_resources_custom_format()` accepts +#' target-specific settings to customize [tar_format()] storage formats. +#' @inheritSection tar_resources Resources +#' @return Object of class `"tar_resources_custom_format"`, to be supplied +#' to the `custom_format` argument of `tar_resources()`. +#' @param envvars Named character vector of environment variables. +#' These environment variables are temporarily set just before each call to +#' the storage methods you define in [tar_format()]. Specific methods +#' like `read` can retrieve values from these environment variables +#' using `Sys.getenv()`. Set `envvars` to `NULL` to omit entirely. +#' @examples +#' # Somewhere in you target script file (usually _targets.R): +#' tar_target( +#' name = target_name, +#' command = data.frame(x = 1), +#' format = tar_format( +#' read = function(path) { +#' readRDS(file = path) +#' }, +#' write = function(object, path) { +#' version <- as.integer(Sys.getenv("SERIALIZATION", unset = "2")) +#' saveRDS(object = object, file = path, version = version) +#' } +#' ), +#' resources = tar_resources( +#' custom_format = tar_resources_custom_format( +#' envvars = c(SERIALIZATION = "3") +#' ) +#' ) +#' ) +tar_resources_custom_format <- function( + envvars = targets::tar_option_get("resources")$custom_format$envvars +) { + out <- resources_custom_format_init( + envvars = envvars + ) + resources_validate(out) + out +} diff --git a/man/tar_resources.Rd b/man/tar_resources.Rd index 1e8905ebe..447966e60 100644 --- a/man/tar_resources.Rd +++ b/man/tar_resources.Rd @@ -8,6 +8,7 @@ tar_resources( aws = tar_option_get("resources")$aws, clustermq = tar_option_get("resources")$clustermq, crew = tar_option_get("resources")$crew, + custom_format = tar_option_get("resources")$custom_format, feather = tar_option_get("resources")$feather, fst = tar_option_get("resources")$fst, future = tar_option_get("resources")$future, @@ -36,7 +37,7 @@ So the correct way to assign \code{clustermq} resources is through \code{\link[=tar_option_set]{tar_option_set()}}, not \code{\link[=tar_target]{tar_target()}}. \code{clustermq} resources in individual \code{\link[=tar_target]{tar_target()}} calls will be ignored.} -\item{crew}{Output of function \code{tar_resources_crew()} +\item{crew}{Output of function \code{\link[=tar_resources_crew]{tar_resources_crew()}} with target-specific settings for integration with the \code{crew} R package. These settings are arguments to the \code{push()} method of the controller or controller group @@ -44,7 +45,10 @@ object which control things like auto-scaling behavior and the controller to use in the case of a controller group.} -\item{feather}{Output of function \code{tar_resources_feather()}. +\item{custom_format}{Output of function \code{\link[=tar_resources_custom_format]{tar_resources_custom_format()}} +with configuration details for \code{\link[=tar_format]{tar_format()}} storage formats.} + +\item{feather}{Output of function \code{\link[=tar_resources_feather]{tar_resources_feather()}}. Non-default arguments to \code{arrow::read_feather()} and \code{arrow::write_feather()} for \code{arrow}/feather-based storage formats. Applies to all formats ending with the \code{"_feather"} suffix. @@ -151,6 +155,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_aws.Rd b/man/tar_resources_aws.Rd index 1a52ce97b..f3d0a87ae 100644 --- a/man/tar_resources_aws.Rd +++ b/man/tar_resources_aws.Rd @@ -157,6 +157,7 @@ Other resources: \code{\link{tar_resources}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_clustermq.Rd b/man/tar_resources_clustermq.Rd index 50d86fa29..8067710c1 100644 --- a/man/tar_resources_clustermq.Rd +++ b/man/tar_resources_clustermq.Rd @@ -69,6 +69,7 @@ Other resources: \code{\link{tar_resources}()}, \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_crew.Rd b/man/tar_resources_crew.Rd index 33aeacd41..b1b0259aa 100644 --- a/man/tar_resources_crew.Rd +++ b/man/tar_resources_crew.Rd @@ -81,6 +81,7 @@ Other resources: \code{\link{tar_resources}()}, \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_custom_format.Rd b/man/tar_resources_custom_format.Rd new file mode 100644 index 000000000..d7783ffd2 --- /dev/null +++ b/man/tar_resources_custom_format.Rd @@ -0,0 +1,89 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tar_resources_custom_format.R +\name{tar_resources_custom_format} +\alias{tar_resources_custom_format} +\title{Target resources for custom storage formats} +\usage{ +tar_resources_custom_format( + envvars = targets::tar_option_get("resources")$custom_format$envvars +) +} +\arguments{ +\item{envvars}{Named character vector of environment variables. +These environment variables are temporarily set just before each call to +the storage methods you define in \code{\link[=tar_format]{tar_format()}}. Specific methods +like \code{read} can retrieve values from these environment variables +using \code{Sys.getenv()}. Set \code{envvars} to \code{NULL} to omit entirely.} +} +\value{ +Object of class \code{"tar_resources_custom_format"}, to be supplied +to the \code{custom_format} argument of \code{tar_resources()}. +} +\description{ +Create the \code{custom_format} argument of \code{tar_resources()} +to specify optional target settings for custom storage formats. +} +\details{ +\code{tar_resources_custom_format()} accepts +target-specific settings to customize \code{\link[=tar_format]{tar_format()}} storage formats. +} +\section{Resources}{ + +Functions \code{\link[=tar_target]{tar_target()}} and \code{\link[=tar_option_set]{tar_option_set()}} +each takes an optional \code{resources} argument to supply +non-default settings of various optional backends for data storage +and high-performance computing. The \code{tar_resources()} function +is a helper to supply those settings in the correct manner. + +In \code{targets} version 0.12.2 and above, resources are inherited one-by-one +in nested fashion from \code{tar_option_get("resources")}. +For example, suppose you set +\code{tar_option_set(resources = tar_resources(aws = my_aws))}, +where \code{my_aws} equals \code{tar_resources_aws(bucket = "x", prefix = "y")}. +Then, \verb{tar_target(data, get_data()} will have bucket \code{"x"} and +prefix \code{"y"}. In addition, if \code{new_resources} equals +\verb{tar_resources(aws = tar_resources_aws(bucket = "z")))}, then +\code{tar_target(data, get_data(), resources = new_resources)} +will use the new bucket \code{"z"}, but it will still use the prefix \code{"y"} +supplied through \code{tar_option_set()}. (In \code{targets} 0.12.1 and below, +options like \code{prefix} do not carry over from \code{tar_option_set()} if you +supply non-default resources to \code{tar_target()}.) +} + +\examples{ +# Somewhere in you target script file (usually _targets.R): +tar_target( + name = target_name, + command = data.frame(x = 1), + format = tar_format( + read = function(path) { + readRDS(file = path) + }, + write = function(object, path) { + version <- as.integer(Sys.getenv("SERIALIZATION", unset = "2")) + saveRDS(object = object, file = path, version = version) + } + ), + resources = tar_resources( + custom_format = tar_resources_custom_format( + envvars = c(SERIALIZATION = "3") + ) + ) +) +} +\seealso{ +Other resources: +\code{\link{tar_resources}()}, +\code{\link{tar_resources_aws}()}, +\code{\link{tar_resources_clustermq}()}, +\code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_feather}()}, +\code{\link{tar_resources_fst}()}, +\code{\link{tar_resources_future}()}, +\code{\link{tar_resources_gcp}()}, +\code{\link{tar_resources_network}()}, +\code{\link{tar_resources_parquet}()}, +\code{\link{tar_resources_qs}()}, +\code{\link{tar_resources_url}()} +} +\concept{resources} diff --git a/man/tar_resources_feather.Rd b/man/tar_resources_feather.Rd index 5be62136d..74cdd0e2e 100644 --- a/man/tar_resources_feather.Rd +++ b/man/tar_resources_feather.Rd @@ -67,6 +67,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, \code{\link{tar_resources_gcp}()}, diff --git a/man/tar_resources_fst.Rd b/man/tar_resources_fst.Rd index b93b405a2..c06401f26 100644 --- a/man/tar_resources_fst.Rd +++ b/man/tar_resources_fst.Rd @@ -60,6 +60,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_future}()}, \code{\link{tar_resources_gcp}()}, diff --git a/man/tar_resources_future.Rd b/man/tar_resources_future.Rd index 699b0a569..d083b2296 100644 --- a/man/tar_resources_future.Rd +++ b/man/tar_resources_future.Rd @@ -76,6 +76,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_gcp}()}, diff --git a/man/tar_resources_gcp.Rd b/man/tar_resources_gcp.Rd index 39574e34c..3ebb19215 100644 --- a/man/tar_resources_gcp.Rd +++ b/man/tar_resources_gcp.Rd @@ -94,6 +94,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_network.Rd b/man/tar_resources_network.Rd index f9ef2c93f..1466ba158 100644 --- a/man/tar_resources_network.Rd +++ b/man/tar_resources_network.Rd @@ -76,6 +76,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_parquet.Rd b/man/tar_resources_parquet.Rd index c3592fa68..d14b85e0b 100644 --- a/man/tar_resources_parquet.Rd +++ b/man/tar_resources_parquet.Rd @@ -66,6 +66,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_qs.Rd b/man/tar_resources_qs.Rd index 5ddd6ba40..6383c2bdf 100644 --- a/man/tar_resources_qs.Rd +++ b/man/tar_resources_qs.Rd @@ -60,6 +60,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/man/tar_resources_url.Rd b/man/tar_resources_url.Rd index b5055e708..e8da6c98f 100644 --- a/man/tar_resources_url.Rd +++ b/man/tar_resources_url.Rd @@ -79,6 +79,7 @@ Other resources: \code{\link{tar_resources_aws}()}, \code{\link{tar_resources_clustermq}()}, \code{\link{tar_resources_crew}()}, +\code{\link{tar_resources_custom_format}()}, \code{\link{tar_resources_feather}()}, \code{\link{tar_resources_fst}()}, \code{\link{tar_resources_future}()}, diff --git a/tests/testthat/test-class_resources_custom_format.R b/tests/testthat/test-class_resources_custom_format.R new file mode 100644 index 000000000..98a942186 --- /dev/null +++ b/tests/testthat/test-class_resources_custom_format.R @@ -0,0 +1,10 @@ +tar_test("create tar_resources_custom_format object", { + x <- resources_custom_format_init(envvars = c(x = "x")) + expect_silent(resources_validate(x)) +}) + +tar_test("print tar_resources_custom_format object", { + x <- resources_custom_format_init(envvars = c(x = "x")) + out <- utils::capture.output(print(x)) + expect_true(any(grepl("tar_resources_custom_format", out))) +}) diff --git a/tests/testthat/test-tar_format.R b/tests/testthat/test-tar_format.R index 28db2e2d4..e0f0eff2e 100644 --- a/tests/testthat/test-tar_format.R +++ b/tests/testthat/test-tar_format.R @@ -96,3 +96,29 @@ tar_test("custom format is not allowed to create a directory", { class = "tar_condition_run" ) }) + +tar_test("custom format envvar resources", { + tar_script( + tar_target( + name = target_name, + command = data.frame(x = 1L), + format = tar_format( + read = function(path) { + readRDS(file = path) + }, + write = function(object, path) { + version <- as.integer(Sys.getenv("SERIALIZATION", unset = "")) + saveRDS(object = object, file = path, version = version) + } + ), + resources = tar_resources( + custom_format = tar_resources_custom_format( + envvars = c(SERIALIZATION = "3") + ) + ) + ) + ) + tar_make(callr_function = NULL) + expect_equal(tar_read(target_name), data.frame(x = 1L)) + expect_equal(Sys.getenv("SERIALIZATION", unset = ""), "") +}) diff --git a/tests/testthat/test-tar_resources_custom_format.R b/tests/testthat/test-tar_resources_custom_format.R new file mode 100644 index 000000000..832f11e13 --- /dev/null +++ b/tests/testthat/test-tar_resources_custom_format.R @@ -0,0 +1,26 @@ +tar_test("tar_resources_custom_format()", { + out <- tar_resources_custom_format() + expect_silent(resources_validate(out)) +}) + +tar_test("tar_resources_custom_format() defaults", { + tar_option_set( + resources = tar_resources( + custom_format = tar_resources_custom_format() + ) + ) + out <- tar_resources_custom_format() + expect_null(out$envvars) +}) + +tar_test("tar_resources_custom_format() non-defaults", { + tar_option_set( + resources = tar_resources( + custom_format = tar_resources_custom_format( + envvars = c(x = "x") + ) + ) + ) + out <- tar_resources_custom_format() + expect_equal(out$envvars, c(x = "x")) +})