I'm currently co-developing an open source package on github, with the eventual goal
of pushing to CRAN. We have written a number of functions, all documented with
roxygen2
and all with the @export
tag, so that they are populated in the NAMESPACE
.
For example a function would be pkgname::foo()
, and a helper function called by foo
would be pkgname::foo_helper()
. The pkgname::foo_helper()
is purely internal i.e.
its only purpose is to help with some computation in pkgname::foo()
, and is not the
focus of our package, but pkgname::foo()
is.
In this example we would like to convert the pkgname::foo_helper()
functions
to "private", as defined by the following criteria:
- The
pkgname::foo_helper()
should by default not appear in the pkgdown>References section, only pkgname::foo()
should appear
- The
pkgname::foo_helper()
function should be fully visible on github i.e. not hidden
- The
pkgname::foo_helper()
functions should be accessible to the R
user by running
pkgname::foo_helper()
, if they want to play with it in R
directly.
What is the best way to make pkgname::foo_helper()
"private" in the above sense.
Also, if we wanted to hide pkgname::foo_helper()
in R
(so user is not distracted by this helper),
what would we change to make them private in this sense?
I assumed that adding a "." at the start of the function name achieves this, but felt there would be
more to it. I was concerned about the implications of removing the @export
tag in roxygen,
especially if other internal package functions relied on these helper functions.
Any help on this is appreciated.
Note: this question is cross-posted here, but has not received any responses after many views, hence posting here for more visibility.
question from:
https://stackoverflow.com/questions/65661317/create-private-helper-functions-in-r-packages 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…