knitr::opts_chunk$set( error = TRUE, collapse = TRUE, comment = "#>", out.width = "100%" )
library(testthat) library(jeksterslabRutils) context("Test util_render.")
tmp_01 <- util_make_subdir() tmp_02 <- util_make_subdir()
extdata
to temporary folderextdata <- system.file( "extdata", "tests", package = "jeksterslabRutils", mustWork = TRUE ) file_from <- file.path( extdata, "z.Rmd" ) file <- file.path( tmp_01, "z.Rmd" ) epub_from <- file.path( extdata, "valid.epub" ) epub <- file.path( tmp_01, "valid.epub" ) output <- file.path( tmp_01, "z.html" ) file.copy( from = c( file_from, epub_from ), to = c( file, epub ) )
html
is produced (dir
)test_that("dir", { skip_on_appveyor() if (file.exists(output)) { unlink(output) } util_render( dir = tmp_01, par = FALSE ) expect_true( file.exists(output) ) })
html
is produced (files
)test_that("files", { skip_on_appveyor() if (file.exists(output)) { unlink(output) } util_render( files = file, par = FALSE ) expect_true( file.exists(output) ) })
message <- "No files to render"
files == 0
test_that("character(0)", { expect_message( util_render( files = character(0), par = FALSE ), regexp = message ) })
test_that("non-existent-file", { expect_message( util_render( files = "non-existent-file", par = FALSE ), regexp = message ) })
test_that("expect_warning", { expect_warning( util_render( files = epub, par = FALSE ), regexp = "Error rendering" ) })
R
or R Markdown
files in dir
.test_that("expect_message", { expect_message( util_render( dir = tmp_02, par = FALSE ), regexp = message ) })
util_clean_dir( dir = tmp_01, create_dir = FALSE ) util_clean_dir( dir = tmp_02, create_dir = FALSE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.