tests/testthat/test-tar_helper.R

tar_test("tar_helper() with one line", {
  path <- tempfile()
  tar_helper(path, x <- 1)
  expect_equal(readLines(path), "x <- 1")
})

tar_test("tar_helper() with more than one line", {
  path <- tempfile()
  tar_helper(path, {
    x <- 1
    y <- 2
  })
  expect_equal(readLines(path), c("x <- 1", "y <- 2"))
})

tar_test("tar_helper() with tidy evaluation", {
  path <- tempfile()
  envir <- new.env(parent = baseenv())
  envir$y <- 1
  tar_helper(path, x <- !!y, tidy_eval = TRUE, envir = envir)
  expect_equal(readLines(path), "x <- 1")
})

tar_test("tar_helper() with tidy evaluation", {
  path <- tempfile()
  envir <- new.env(parent = baseenv())
  envir$y <- 1
  tar_helper(path, x <- !!y, tidy_eval = FALSE, envir = envir)
  expect_equal(readLines(path), "x <- !!y")
})

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.