Tao Shi
2008-Oct-08 00:13 UTC
[R] follow up on "[Rd] NAMESPACE & methods guidance, please" ( http://tolstoy.newcastle.edu.au/R/e4/devel/08/06/1901.html )
This is a follow-up on the discussion originally posted on the R-devel list ( http://tolstoy.newcastle.edu.au/R/e4/devel/08/06/1901.html ), as I have encountered the exact same issue mentioned in Martin's email. Here is a simplified version of my problem: ##================================================================## I created a package, say, "tmpA", with a NAMESPACE with Depend: and Imports: org.Hs.eg.db and in a new session of R> library(tmpA) > foofunction () { require("org.Hs.eg.db") get("A GO TERM", org.Hs.egGO2ALLEGS) }> foo()Error in as.environment(pos) : invalid object for 'as.environment' ##================================================================ I fixed the problem by changing "get" explicitly to "AnnotationDbi::get". I'm just wondering what was the final decision on the problem and if there are more elegant ways of handling this. Thanks, ...Tao _________________________________________________________________ 50F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
Martin Morgan
2008-Oct-09 18:26 UTC
[R] follow up on "[Rd] NAMESPACE & methods guidance, please" ( http://tolstoy.newcastle.edu.au/R/e4/devel/08/06/1901.html )
Hi Tao -- Tao Shi <shitao at hotmail.com> writes:> This is a follow-up on the discussion originally posted on the > R-devel list ( > http://tolstoy.newcastle.edu.au/R/e4/devel/08/06/1901.html ), as I > have encountered the exact same issue mentioned in Martin's email. > Here is a simplified version of my problem: > > > ##================================================================> ## I created a package, say, "tmpA", with a NAMESPACE with Depend: > and Imports: org.Hs.eg.db and in a new session of R > >> library(tmpA) >> foo > > function () > { > > require("org.Hs.eg.db") > get("A GO TERM", org.Hs.egGO2ALLEGS) > } > > >> foo() > > Error in as.environment(pos) : invalid object for 'as.environment' > ##================================================================> > > I fixed the problem by changing "get" explicitly to > "AnnotationDbi::get". I'm just wondering what was the final > decision on the problem and if there are more elegant ways of > handling this.I think this is a matter of programming style. Likely your package manipulates different annotation packages, so it might make sense to Import: AnnotationDbi (or Depends:, but only if the end user will need to directly use AnnotationDbi functionality). In the NAMESPACE, you might then importFrom(AnnotationDbi, get). All uses of 'get' inside your package now see AnnotationDbi's 'get' methods. Since you 'require' org.Hs.eg.db, it sounds like this is a package that belongs in 'Suggests:' not 'Depends'. Follow-ups might go to bioc-devel. Martin> Thanks, > > ...Tao > > > > _________________________________________________________________ > > > 50F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008 > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (206) 667-2793