R/test-helpers.R

Defines functions expect_snapshot_data save_csv

save_csv <- function(x) {
  path <- tempfile(fileext = ".csv")
  utils::write.csv(x, path, quote = FALSE, row.names = FALSE)
  path
}

expect_snapshot_data <- function(x, name, digits = 6) {
  fun <- function(x) signif(x, digits = digits)
  x <- as.list(x)
  x <- purrr::map_if(x, .p = is.numeric, .f = signif, digits = digits)
  x <- as.data.frame(x)
  path <- save_csv(x)
  testthat::expect_snapshot_file(
    path,
    paste0(name, ".csv"),
    compare = testthat::compare_file_text
  )
}

Try the mcmcr package in your browser

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

mcmcr documentation built on April 3, 2025, 6:06 p.m.