tidymodels / model-implementation-principles

recommendations for creating R modeling packages
https://tidymodels.github.io/model-implementation-principles/
41 stars 4 forks source link

Add section on how to test models #9

Open alexpghayes opened 5 years ago

alexpghayes commented 5 years ago

Things that should be included:

Some of this should overlap with the R package book (see related issues https://github.com/hadley/r-pkgs/issues/477, https://github.com/hadley/r-pkgs/issues/481).

alexpghayes commented 5 years ago

In particular we may want to provide advice on how to test against the Python ecosystem since it's such a nightmare to get that all set up

DavisVaughan commented 5 years ago

For yardstick, I took the approach of saving small output files for later use in tests.

One file generates them, and they just sit in the tests/ folder: https://github.com/tidymodels/yardstick/tree/master/tests/pycompare

I needed a helper for reading in the files so the same path could work interactively and during a CTRL+SHIFT+T test run (testthat changes the path). https://github.com/tidymodels/yardstick/blob/master/tests/testthat/helper-read_pydata.R

And then the actual tests are fairly simple: https://github.com/tidymodels/yardstick/blob/master/tests/testthat/test-class-precision.R#L24