3
votes

I created a package with some functions which are helpful at my company. Recently, I restructered the package such that there are helper functions which need not to be accessible for everyone, but are called internally from other (exported) functions of the package. These helper functions are not exported to the namespace (no #' @export in the respective .R files).

Now, when I call one of the "major" (exported) functions, I get the error message (no real function names):

Error in major_function() : could not find function "helper_function"

Im fairly new in building packages, but from what I understood so far (from https://cran.r-project.org/web/packages/roxygen2/vignettes/namespace.html), it should neither be necessary to export the helper functions, nor to add #' importFrom my_package helper_function to the .R file of the major function.

When I tried this, it actually produced errors when checking the package. I also tried to call the helper functions with my_package:::helper_function, but this lead to the note that it should almost never be necessary to call functions from the same package like this.

Maybe useful information:

The error occurs only when I call a major_function_1 which internally calls major_function_2 which calls a helper_function.

1

1 Answers

1
votes

I think there is more to your problem than what you state. As long as all your functions are defined in the same namespace (this also means that all your functions need to live in .R files in the same folder), the calling function should find the helper-functions accordingly. I suspect you have your helper functions nested in some way, and that is causing the problem.

I recommend to recheck your namespace structure, or post a simplistic outline of your package here.

Another reason that could come to mind, is that you do not export your 'mayor_function2' in your NAMESPACE-file in your package root (maybe you have not recompiled the Roxygen documentation generating this file), and additionally have a local shadow of the the calling function 'mayor_function1'. Try to check this and rerun from a clean compile.