test-formats.R 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. test_format <- function(name, os_skip = NULL) {
  2. # don't run on CRAN due to complicated dependencies (Pandoc/LaTeX packages)
  3. if (!identical(Sys.getenv("NOT_CRAN"), "true")) return()
  4. # skip on OS if requested
  5. if (!is.null(os_skip)) return()
  6. # work in a temp directory
  7. dir <- tempfile()
  8. dir.create(dir)
  9. oldwd <- setwd(dir)
  10. on.exit(setwd(oldwd), add = TRUE)
  11. # create a draft of the format
  12. testdoc <- paste0(name, ".Rmd")
  13. rmarkdown::draft(
  14. testdoc, system.file("rmarkdown", "templates", name, package = "rticles"),
  15. create_dir = FALSE, edit = FALSE
  16. )
  17. message('Rendering the ', name, ' format...')
  18. output_file <- rmarkdown::render(testdoc, quiet = TRUE)
  19. assert(paste(name, "format works"), {
  20. file.exists(output_file)
  21. })
  22. }
  23. test_format("acm_article")
  24. test_format("acs_article")
  25. test_format("aea_article")
  26. test_format("ams_article")
  27. test_format("asa_article")
  28. test_format("elsevier_article")
  29. test_format("jss_article")
  30. test_format("rss_article")
  31. test_format("pnas_article")
  32. test_format("ieee_article")
  33. test_format("rjournal_article")
  34. test_format("sage_article")
  35. test_format("sim_article")
  36. test_format("peerj_article")
  37. test_format("amq_article")
  38. test_format("mdpi_article")
  39. test_format("mnras_article")
  40. test_format("copernicus_article")