1. Learn
  2. /
  3. Courses
  4. /
  5. Creating R Packages

Exercise

Setting up the test structure

You can set up a test framework in a package using the function use_testthat().

This will create a tests directory that contains:

  • A script testthat.R.
  • A directory testthat.

You save your tests in the tests/testthat/ directory in files with filenames beginning with test-. So, for example, the simutils package has tests named:

  • test-na_counter.R
  • test-sample_from_data.R

There are no other strict rules governing the filenames, but you may find it easier to keep track of which functions you are testing if you name your tests after the functions like in the examples above. Alternatively, you can name your tests after areas of package functionality, for example, putting tests for multiple summary functions in test-summaries.R.

Instructions

100 XP
  • Set up the test framework for your datasummary package.
  • Look at the contents of the package root directory.
  • Look at the contents of the new folder which has been created.