Invisible functions / methods in R - how are they made?

How to define functions (methods) invisible to the user? Those that are marked with an asterisk when you call methods() on them.

The Internet seems to have everything about them, but how do you define them?

Is it possible to simply define an invisible function (for example, adding something to its name), or do I need to somehow configure the environment, or is it a special feature of R packages to hide things?

+8
function methods r hidden
source share
1 answer

These are "hidden" functions. You may find this (warning pdf) useful. This can be done when you create the package in the NAMESPACE file, which is part of the nuts and bolts of the R package. Here is the full text from the NAMESPACE file for the bilan package (you can find it by opening the source code for the tar.gz package with CRAN ):

 useDynLib (bilan)
 exportPattern ("^ bil \\. [[: alpha:]] +")
 exportPattern ("^ sbil \\. [[: alpha:]] +")

From the above document:

To have hidden features. Replace the exportPattern command with the export command, where the export arguments are comma-separated names of functions that should be available to users

Basically, if you created an R package with two functions foo and bar , you can make a NAMESPACE file with the export(foo) , and then bar will be a hidden function.

+6
source share

All Articles