3  Enriching package functionalities

Aims
  • Adding supporting data
  • Adding examples
  • Adding unit tests
  • Check package
Tip

At any time, if you are lost or do not understand how functions in the proposed solution work, type ?<function> in the R console and a help menu will appear.

You can also check the help tab in the corresponding quadrant.

Reminder

We aim to create a package which can plot the aggregated coverage of a genomic track over a set of GRanges of interest (at a fixed width).

3.1 Add supporting data to your package

You can use toy dataset files provided in Share/Day3/.

Question

Add them to the inst/extdata/ folder in your package.

You will also need to document how these raw data files have been generated (or obtained). This can be done in a less “formal” manner, in a .R file in inst/scripts.

Tip

An example of such script is in Share/Day3/make-extdata.R.

3.2 Add examples to your function files

Examples can be used to illustrate how your function works. They are integrated in the manual pages compiled with document() and are often the first thing a new end-user is going to read.

Question

Add runnable examples to each function.

Once you have added examples to your functions, you can check whether these examples work with run_examples().

run_examples()
Tip

The content of the proposed function files is shown in Share/Day3/functions_with-examples/. These files provides an example of implementation to fulfill our package’s requirements, with examples added.

3.3 Add unit tests to your package

Unit tests are the best way to make sure that your package works as intended. They consist of R code, executed and compared to an expected result.

To start using unit tests, you need to declare it. We will use the testthat framework to implement unit tests.

usethis::use_testthat()
Question

Once testthat is initiated, create a new test file and add individual tests.

usethis::use_test("")
Tip

An example of a working test file is availabe in Share/Day3//

3.4 Check your package

Several check functions are available. They each check your package in a specific way.

  • devtools::check() verifies the basic structure of the package, the documentation, the examples and unit tests;
  • rcmdcheck::rcmdcheck() does somewhat the same job but builds the package first;
  • BiocCheck::BiocCheck() checks the compliance of the package with Bioconductor requirements.
check()
rcmdcheck::rcmdcheck()
BiocCheck()
Question

Attempt to fix the ERROR and WARNING returned by check() and BiocCheck().