tests/testthat/test-save_and_load.R

test_that("save numbers in JSON works", {

  # set no hashing
  options(reproducibleRchunks.hashing = FALSE)
  mydata <- 1:10
  filename <- tempfile()
  reproducibleRchunks::save_repro_data(c("mydata"),
                                        filename = filename,
                                        filetype = "json")

  on.exit({
    unlink(filename)
  }, add = TRUE)

  test_envir <- new.env()
  reproducibleRchunks::load_repro_data(filename,
                                        filetype = "json",
                                        envir = test_envir)

  testthat::expect_identical(ls(test_envir), "mydata")
  testthat::expect_identical(get("mydata", envir = test_envir), mydata)

})

Try the reproducibleRchunks package in your browser

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

reproducibleRchunks documentation built on Aug. 8, 2025, 6:38 p.m.