tests/testthat/test-tar_group.R

tar_test("tar_group() works", {
  skip_cran()
  skip_if_not_installed("dplyr")
  out <- data_frame(
    x = seq_len(6),
    id = rep(letters[seq_len(3)], each = 2)
  )
  out <- dplyr::group_by(out, id)
  out <- tar_group(out)
  exp <- data_frame(
    x = seq_len(6),
    id = rep(letters[seq_len(3)], each = 2),
    tar_group = rep(seq_len(3), each = 2)
  )
  expect_equiv(out, exp)
})

tar_test("tar_group() needs group_by()", {
  skip_cran()
  skip_if_not_installed("dplyr")
  out <- data_frame(
    x = seq_len(6),
    id = rep(letters[seq_len(3)], each = 2)
  )
  expect_error(tar_group(out), class = "tar_condition_validate")
})

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.