[Rd] accessing hidden functions in testing code

Tony Plate tplate at acm.org
Wed Apr 11 19:29:42 CEST 2007

I'd like to be able to access unexported functions in the testing code 
for a package with a namespace.  I know that one way to do this is to 
use the ":::" operator, but I'd prefer to avoid cluttering up my testing 
code with lots of repetitions of "myPackageName:::".

One way I found to do this was to attach() the namespace of the package, 
e.g., using the following:

pkg <- "myPackageName"
library(package=pkg, character.only=TRUE)
## --- Load the name space to allow testing of private functions ---
if (is.element(pkg, loadedNamespaces()))
     attach(loadNamespace(pkg), name=paste("namespace", pkg, sep=":"), 

Are there any pitfalls that I will find if I continue with this 
approach?  Or is there another better way?

-- Tony Plate

More information about the R-devel mailing list