tests/testthat/test-cran-examples-regression.R

test_that("usedf handles a read-only package dataset as an unlinked copy", {
  on.exit(try(usedf(clear = TRUE, quiet = TRUE), silent = TRUE), add = TRUE)
  expect_no_error(usedf(iris, quiet = TRUE))
  z <- usedf(quiet = TRUE)
  expect_s3_class(z, "data.frame")
  expect_equal(nrow(z), 150L)
})

test_that("keepvar wildcard example preserves the source template", {
  d <- data.frame(
    id = 1:5,
    age = c(10, 20, NA, 40, 50),
    sex = c("M", "F", "F", "M", "F"),
    score_a = 1:5,
    score_b = 6:10
  )

  d1 <- d
  keepvar(d1, id, age, sex)
  expect_identical(names(d1), c("id", "age", "sex"))

  d3 <- d
  expect_no_error(keepvar(d3, id, "score_*"))
  expect_identical(names(d3), c("id", "score_a", "score_b"))
})

Try the R4VN package in your browser

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

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.