tests/testthat/test-tar_load_globals.R

tar_test("tar_load_globals", {
  tar_script({
    tar_option_set(packages = "callr")
    analyze_data <- function(data) {
      summary(data)
    }
    list(
      tar_target(x, 1 + 1),
      tar_target(y, 1 + 1)
    )
  }, ask = FALSE)
  envir <- new.env(parent = globalenv())
  tar_load_globals(envir = envir)
  expect_true(is.function(envir$analyze_data))
  expect_true("callr" %in% (.packages()))
})

Try the targets package in your browser

Any scripts or data that you put into this service are public.

targets documentation built on Oct. 12, 2023, 5:07 p.m.