Unit testing is a core component to building R packages (and software in general). The R Packages book goes into more detail here: https://r-pkgs.org/testing-basics.html
I set this up with usethis::use_testthat() and then I added a unit test file for one script by opening that file (preprocessing.R) and running usethis::use_test(). Each unit test you write should test one thing, in this case, I am testing that the preprocessing zero-centers the data. With testing, you always use the "actual" values, and compare with what you expect it should be. In general, for every "user facing function", you should write as many unit tests as you can to confirm that it gives the output that you expect the function to output. This part of coding is also one of the harder ones.
Unit testing is a core component to building R packages (and software in general). The R Packages book goes into more detail here: https://r-pkgs.org/testing-basics.html
I set this up with
usethis::use_testthat()
and then I added a unit test file for one script by opening that file (preprocessing.R
) and runningusethis::use_test()
. Each unit test you write should test one thing, in this case, I am testing that the preprocessing zero-centers the data. With testing, you always use the "actual" values, and compare with what you expect it should be. In general, for every "user facing function", you should write as many unit tests as you can to confirm that it gives the output that you expect the function to output. This part of coding is also one of the harder ones.