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

1

10

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?

Netherlands answered 24/12, 2013 at 3:30 Comment(0)
S
9

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.

Swot answered 24/12, 2013 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.