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

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Jun 7 08:03:09 CEST 2006


On Wed, 2006-06-07 at 01:14 -0400, Dan Rabosky wrote:
> Hello.
> 
> I am creating an R package that I'd like to submit to CRAN (OS Windows 
> XP).  How do I distinguish among 'public' functions, e.g., those that are 
> intended to be called by users of the package and for which I am providing 
> documentation & examples, and 'private' functions, which are used 
> internally by the 'public' functions, but for which I do not wish to 
> provide documentation?  The private functions are all coded in R (nothing 
> in C or Fortran) and are essential to the operation of several public 
> functions.

Hi Dan,

The answer is in the Writing R Extensions manual.

You could do either:

        1) Put the code for your "private" functions in a file names
        internal.R. You then provide a simple file named
        <package-name>-internal.Rd which lists in individual \alias{}
        markup the names of the private functions, eg;
        
        \name{mypackage-internal}
        \alias{foo1}
        \alias{foo2}
        \alias{foo3}
        \alias{foo4}
        \title{Internal mypackage Functions}
        \description{
          Internal mypackage functions
        }
        \details{
          These are not to be called by the user.
        }
        \keyword{ internal }
        
        But even here, you aren't documenting the internal functions,
        just working round the package checks.
        
        2) Place your package in a namespace, which is documented fully
        in Writing R Extensions.

Not sure what the best advice is - I'd guess that for all but the
simplest packages, namespaces are the preferred way, but the internal.R
way works just fine also.

By the way, in future, questions of this nature are best asked on the
R-Devel list, not here.

HTH,

Gavin



More information about the R-help mailing list