My package is not recognizing the exported functions of an imported package in R

I am writing an R package. Using roxygen2, I have this processor statement:

##' @import Other_Package

As I understand it, this statement would import every exported function from Other_Package. But when I ran:

devtools::test()

Some test cases failed because it wasn't able to find some functions of Other_Package.

Upvotes: 1

Views: 185

Answers (1)

Dave Gruenewald
Dave Gruenewald

Reputation: 5689

Make sure to include Other_Package in you DESCRIPTION file. You can do this very readily with:

usethis::use_package("Other_Package")

Additionally, make sure you re-render your documentation before tests. This will include recreating your NAMESPACE file. roxygen2 is great and will handle this part for you:

devtools::document()

To confirm, go to your NAMESPACE file and make sure import(Other_Package) is found there. When using roxygen2, do NOT edit the NAMESPACE file by hand.

Now, your tests should run normally:

devtools::test()

Alternative Solutions

Rather than relying on your NAMESPACE, I'd recommend you make explicit calls inside your package. So any function from Other_Package would have the Other_Package:: prefix (e.g. function1() would be Other_Package::function1()). Do this throughout your entire package, including any tests.

Upvotes: 2

Related Questions