[R] Building packages in R - 'private' functions

Seth Falcon sfalcon at fhcrc.org
Wed Jun 7 16:29:47 CEST 2006

"Antonio, Fabio Di Narzo" <antonio.fabio at gmail.com> writes:

> 1. If you have time to change internal functions naming, you can rename
> internal functions by putting a leading '.'.
> Even without namespace, I have noticed there is no check for corresponding
> docs for such functions.
> 2. If you don't want to rename all internal functions, the best way is
> writing an 'internals.Rd' file with an alias for each internal function
> (documented in 'writing R extensions').
> 3.Finally, you can add a NAMESPACE (see writing R extensions). However, if
> you use S3/S4 classes, this can be much more tedious to do.
> I think the no. 2 to be the fastest/safer way.

I think adding a NAMESPACE file is the best solution and I don't think
that the process needs to be particularly tedious.

Having a naming convention for private functions is fine and you can
still do that with a NAMESPACE.  Non-exported functions do not get
checked for documentation, so there is no need for an internals.Rd (of
course, it doesn't hurt to give yourself some documentation for when
you return to the project 3 months later :-)

Besides hiding your private functions, a NAMESPACE protects you from
users or other packages redefining functions that you rely on.  As an
extreme example, if a user redefined length(), many packages without
namespaces would break.

+ seth

More information about the R-help mailing list