2

I'm developing an R package, pk, say. I've successfully installed it and used it, and now I'm trying to clean up the examples with the help of the run_examples function in the devtools package. However, it crashes on the very first example:

> require(pk)
> require(devtools)
> run_examples("~/[full path]/pk")
Updating pk documentation
Running 45 example files in pk
--------------------------------------------------------------------------------
Loading pk
Running examples in pk-package.Rd
--------------------------------------------------------------------------------

1> ########################################################################
1> ## Simulate a dataset ... blah blah
1> set.seed(1)
1> x = my_pk_fun(a = 1)
Error in eval(expr, envir, enclos) : could not find function "my_pk_fun"
Loading pk

As I already loaded my package (using require), what more do I have to do to make my_pk_fun visible to run_examples? I've checked that my_pk_fun is indeed present in my R session.

UPDATE: Following the comment by Dirk, I examined my namespace file, and found it to be completely empty. As suggested (though not recommended) by the documentation, I inserted exportPattern("^[^\\.]"), which, it seems, is supposed to export all of the functions, including my_pk_fun. However, upon repeating the experiment above, (a) I get the same error, and (b) the contents of the namespace file are deleted! Why does run_examples empty my namespace file?

zkurtz
  • 3,230
  • 7
  • 28
  • 64

1 Answers1

0

I conjecture a resolution of my own question:

One detail that I omitted is that before I could get run_examples to do anything at all, it required me to first install the roxygen2 package (even though roxygen2 is listed only under "suggests" in the devtools documentation!).

When digging through the source code of run_examples, I did indeed find some use of roxygenize. It has been previously noted that roxygenizing a package can have the effect of rewriting the NAMESPACE file.

To be explicit, the reason that run_examples empties my NAMESPACE file is that (1) run_examples roxygenized my package while (2) I never included any # @export command (or any other roxygen2-speak, for that matter) in my source files.

Conclusion: Unless you are building your package within the roxygen2 framework, and including all of your .Rd documentation as comments in your source code, then do not use run_examples! It seems like there should be a warning about this in the run_examples documentation.

A way out: If you really must use run_examples, and you're willing to learn a little bit about roxygen, which is actually pretty cool, then start here.

Community
  • 1
  • 1
zkurtz
  • 3,230
  • 7
  • 28
  • 64