Closed Melkiades closed 2 years ago
Based on the blog you mentioned,
tests/testthat.R
tests/testthat/
whose name starts with setup
are loaded before tests are runI think these are novel approaches to prevent repetitive data loading and therefore improve test performance.
So tests/testthat/setup-data.R
would look something like this?
library(scda)
library(scda.2022)
test_data <- scda::synthetic_cdisc_data("rcd_2022_02_28")
Exactly. I also changed testthat.R
in Rtables to reflect the "do-not-touch" policy. I think adding setup-libraries.R
and setup-data.R
is a possible nice solution to repetitions and too many mods to be made.
Need to be careful though as test_data
will be shared by all tests so if something changes it you could be in a world of pain.
You may want to have
load_data <- function(date) {
scda::synthetic_cdisc_data(date)
}
memoise_load_data <- memoise::memoise(load_test_data)
At the moment data from
scda
is loaded multiple times (~9.9Mb of data each time) and libraries that are only suggested bytern
are loaded multiple times at the beginning of each long test file. I strongly suggest following this post and the issue I filed in rtables#393. In other words, I think the best way to go here is to update the setup file intestthat/
with the libraries needed across tests and add a helper file with data loading (always intestthat/
) so they are both done once before tests are run. This would cut down test time and useless complexity and repetition across tests. Also, we need to consider if we should be usingwithr
, but this is related to a later stage imo, when we have a more reasonable data caching design (as discussed here). A tentative list of things to do here:scda
-based ones).withr
.What do you think @cicdguy @shajoezhu ?