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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With