NAMESPACES, export, and unit tests
4
0
Entering edit mode
Paul Shannon ▴ 40
@paul-shannon-1707
Last seen 10.2 years ago
Hi all, In a package ('gaggle') I am about to submit to Bioc, I have run into a small problem. 1) In inst/unitTests/gaggleTest.R I call two functions from gaggle.R which are otherwise hidden. .gaggleNetworkToGraphNEL .graphNELtoGaggleNetwork It is very helpful to call these methods in gaggleTest, since their proper operation is crucial for the gaggle package. 2) Now that I am using NAMESPACES, it seems I can't call these methods in gaggleTest.R unless they are explicitly exported from gaggle.R 3) But if I do export them, then they (along with the .Rd files I would then need to create) would be visible to regular users; that seems like a bad idea. Is there any other way to make these two functions available to the unitTest program? Anything, perhaps, like the C++ friend construct, or the Java convention of allowing multiple classes in the same package access to otherwise-hidden methods? Thanks - Paul Shannon
gaggle gaggle • 1.1k views
ADD COMMENT
0
Entering edit mode
Seth Falcon ★ 7.4k
@seth-falcon-992
Last seen 10.2 years ago
Hi Paul, Paul Shannon <pshannon at="" systemsbiology.net=""> writes: > 1) In inst/unitTests/gaggleTest.R I call two functions from gaggle.R > which are otherwise hidden. > > .gaggleNetworkToGraphNEL > .graphNELtoGaggleNetwork > > It is very helpful to call these methods in gaggleTest, since > their > proper operation is crucial for the gaggle package. > > 2) Now that I am using NAMESPACES, it seems I can't call > these methods in gaggleTest.R unless they are explicitly > exported from > gaggle.R One option is to use the ':::' function. This allows one to override namespace protection. For example, in your test code you could call: gaggle:::.gaggleNetworkToGraphNEL() ':::' can be dangerous; non-exported functions can change without notice. If you are using it with your own package, well, that seems safe enough :-) + seth
ADD COMMENT
0
Entering edit mode
But the question is: do we consider it a feature for the unit tests not being able to access the non-exported objects in the normal way... or is it a bug? I'm asking because there seems to be other things that you can't do in the unit tests (like defining S4 classes or dispatching on an S4 class defined somewhere in the package, I don't remember exactly). I'm wondering what's the motivation behind these restrictions... H. Seth Falcon wrote: >One option is to use the ':::' function. This allows one to override >namespace protection. For example, in your test code you could call: > > gaggle:::.gaggleNetworkToGraphNEL() > >':::' can be dangerous; non-exported functions can change without >notice. If you are using it with your own package, well, that seems >safe enough :-) > >+ seth > >_______________________________________________ >Bioconductor mailing list >Bioconductor at stat.math.ethz.ch >https://stat.ethz.ch/mailman/listinfo/bioconductor >Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > > -- ------------------------ Hervé Pagès E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319
ADD REPLY
0
Entering edit mode
@kasper-daniel-hansen-2979
Last seen 17 months ago
United States
And if you are starting to use namespaces you should really read the R-news article about namespaces (as far as I recall it was written by Luke Tierney). /Kasper On May 1, 2006, at 12:43 PM, Paul Shannon wrote: > Hi all, > > In a package ('gaggle') I am about to submit to Bioc, I have > run into a small problem. > > 1) In inst/unitTests/gaggleTest.R I call two functions from > gaggle.R > which are otherwise hidden. > > .gaggleNetworkToGraphNEL > .graphNELtoGaggleNetwork > > It is very helpful to call these methods in gaggleTest, since > their > proper operation is crucial for the gaggle package. > > 2) Now that I am using NAMESPACES, it seems I can't call > these methods in gaggleTest.R unless they are explicitly > exported from > gaggle.R > > 3) But if I do export them, then they (along with the .Rd files I > would then > need to create) would be visible to regular users; that seems > like a bad idea. > > Is there any other way to make these two functions available to the > unitTest > program? Anything, perhaps, like the C++ friend construct, or the > Java > convention of allowing multiple classes in the same package access to > otherwise-hidden > methods? > > Thanks - > > Paul Shannon > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/ > gmane.science.biology.informatics.conductor
ADD COMMENT
0
Entering edit mode
Seth Falcon ★ 7.4k
@seth-falcon-992
Last seen 10.2 years ago
I'm going to move this discussion over to bioc-devel. Interested parties, please respond there... + seth
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 10 minutes ago
United States
Hi Paul, Paul Shannon wrote: > Hi all, > > In a package ('gaggle') I am about to submit to Bioc, I have > run into a small problem. > > 1) In inst/unitTests/gaggleTest.R I call two functions from gaggle.R > which are otherwise hidden. > > .gaggleNetworkToGraphNEL > .graphNELtoGaggleNetwork > > It is very helpful to call these methods in gaggleTest, since > their > proper operation is crucial for the gaggle package. > > 2) Now that I am using NAMESPACES, it seems I can't call > these methods in gaggleTest.R unless they are explicitly > exported from > gaggle.R > > 3) But if I do export them, then they (along with the .Rd files I > would then > need to create) would be visible to regular users; that seems > like a bad idea. > > Is there any other way to make these two functions available to the > unitTest > program? There may be a more elegant solution, but one way would be to use the triple colon operator: gaggle:::.gaggleNetworkToGraphNEL will make this function available. HTH, Jim Anything, perhaps, like the C++ friend construct, or the Java > convention of allowing multiple classes in the same package access to > otherwise-hidden > methods? > > Thanks - > > Paul Shannon > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.
ADD COMMENT

Login before adding your answer.

Traffic: 947 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6