testthat

How to write a test for a ggplot plot

夙愿已清 提交于 2019-11-29 04:50:45
问题 I have a lot of functions that generate plots, typically with ggplot2. Right now, I'm generating the plot and testing the underlying data. But I'd like to know if there's a reasonable way to test that the plot contains the layers/options I expect it to or that graphical elements match expectations. For example: library(ggplot2) library(scales) # for percent() library(testthat) df <- data.frame( Response = LETTERS[1:5], Proportion = c(0.1,0.2,0.1,0.2,0.4) ) #' @export plot_fun plot_fun <-

Where should I put data for automated tests with testthat?

社会主义新天地 提交于 2019-11-27 12:00:39
问题 I am using Hadley's testthat-based approach for automated testing of my package. With this approach, what is the most suitable place to put test data files that is files only used by the test scripts in tests/testthat), but not by any other functions in R/? My current approach is to put them in tests/testdata , and then read.table from there with a relative path rather than with system.file (in order to avoid the need to install the package to run tests). Is there a standard way to do this?