tests/testthat/test-tar_seed.R

tar_test("tar_seed() outside a pipeline", {
  expect_equal(tar_seed(), 1L)
  expect_equal(tar_seed(default = 123L), 123L)
})

tar_test("tar_seed() inside a pipeline", {
  x <- target_init("x", quote(targets::tar_seed(default = 1L)))
  local_init(pipeline_init(list(x)))$run()
  expect_true(is.integer(target_read_value(x)$object))
  seed <- target_read_value(x)$object
  expect_false(seed == 1L)
  tar_destroy()
  x <- target_init("x", quote(targets::tar_seed(default = 1L)))
  local_init(pipeline_init(list(x)))$run()
  expect_identical(target_read_value(x)$object, seed)
})

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.