tests/testthat/test-read-builtin.R

test_that("read_builtin works", {
  skip_if(interactive())
  # fails with unquoted symbol (like data(storms, package = "dplyr"))
  expect_error(read_builtin(storms, "dplyr"))

  # fails with error if the dataset namespace is not attached
  unloadNamespace("dplyr")
  expect_error(
    read_builtin("storms")
  )
  # fails with an error if data set doesn't exist in package
  expect_error(
    read_builtin("nasa", "readr")
  )
  # works if data set exists in package
  expect_true(is.data.frame(read_builtin("storms", "dplyr")))
  # works if data set package is loaded
  library(dplyr)
  expect_true(is.data.frame(read_builtin("storms")))
})

Try the readr package in your browser

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

readr documentation built on Aug. 10, 2021, 5:06 p.m.