Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non visible functions/methods in R -- how are they made?

How to define functions (methods) invisible to the user? Those which are asterisked when you call methods() on them.

It seems there is everything about them on the internet, but how to define them?

Can I just define a non-visible function (by adding something to its name for example), or should I tweak the environment somehow, or is it a particular feature of R packages to hide stuff?

like image 459
xealits Avatar asked Dec 24 '13 03:12

xealits


1 Answers

These are "hidden" functions. You might find this (warning pdf) useful. You can do it when you design a package in the NAMESPACE file included as part of the nuts and bolts of an R package. Here's the full text from the NAMESPACE file for the bilan package (can be found by opening up package source code tar.gz file from CRAN):

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

From the pdf mentioned above:

To have hidden functions. Replace the exportPattern command with an export command, where export's arguments are comma-separated function names that should be accessible to users

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

like image 118
alex keil Avatar answered Oct 19 '22 00:10

alex keil