Balazs Dukai Balazs Dukai - 7 months ago 24
R Question

Why does devtools::document() try to document tests?

I'm working on a package (this one) where I set up my tests according to the testthat workflow. This includes having my tests in

folder and a
file as follows:


All the tests require that the
package is attached (thus I didn't use the

Just after restarting R (without
attached) I try to run
but it breaks, because it doesn't find the
functions that I use in the tests. Of course, after attaching
runs through.

Why does
look into the
folder? Shouldn't it only document functions in the

Answer Source

devtools::document() is a wrapper for roxygen2::roxygenize. If you read the documentation of the latter it says:

Note that roxygen2 is a dynamic documentation system: it works using by inspecting loaded objects in the package. This means that you must be able to load the package in order to document it.

And also there is an argument load_code which says:

A function used to load all the R code in the package directory. It is called with the path to the package, and it should return an environment containing all the sourced code.

Therefore, it looks like it is reading all .R files. However, I have a feeling that it skips all .R files that start with test_ in the name (otherwise I would have seen my packages break as well). I think the problem is your helper_db.R file where you use testthat functions in a file not starting with test_.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download