[BioC] Using annotation maps as environments in packages
Hervé Pagès
hpages at fhcrc.org
Thu Mar 4 20:51:37 CET 2010
Hi Antti,
Antti Honkela wrote:
> Hi all,
>
> I have a weird problem when I try to write a function in a package that
> would use annotation maps (e.g. mouse430a2SYMBOL) as an environment that
> the function works on its own breaks when moved into a package.
>
> The maps can usually be used as environments without problems and the
> following works fine:
> > library(mouse430a2.db)
> > get("1419728_at", env=mouse430a2SYMBOL)
>
> The same is true if I define an own function to access the map, and this
> runs without problems:
> > getAnnotation <- function(gene, env) { return (get(gene, env=env)) }
> > getAnnotation("1419728_at", env=mouse430a2SYMBOL)
>
> However, if I move the same function definition to an independent
> package, the same call results in an error:
> > getAnnotation("1419728_at", env=mouse430a2SYMBOL)
> Error in get(gene, env = env) : invalid 'envir' argument
I think you need to put a NAMESPACE to your package (you probably
already have one) and import the AnnotationDbi package. This is done
by putting AnnotationDbi in the Imports field of your DESCRIPTION
file and by adding the import(AnnotationDbi) directive to your
NAMESPACE file. Also you need to do the same for the methods
package (put it preferably first i.e. before AnnotationDbi).
Otherwise code in your package doesn't "see" the "get" generic and
its methods that are defined in AnnotationDbi and your calls to get()
are in fact calls to base::get(), which is why you get this error.
Let us know if that doesn't solve the problem.
Cheers,
H.
>
> Any ideas how to fix or circumvent this?
>
> (Note that in the sessionInfo below, testpkg is a minimal package only
> containing the above function definition.)
>
>
> Best regards,
>
> Antti
>
> ---------------------------------------------------------
> > sessionInfo()
> R version 2.10.1 (2009-12-14)
> i386-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] mouse430a2.db_2.3.5 org.Mm.eg.db_2.3.6 RSQLite_0.7-3
> DBI_0.2-4 AnnotationDbi_1.8.1 Biobase_2.6.0
> [7] testpkg_0.0-1
>
> loaded via a namespace (and not attached):
> [1] affy_1.24.2 affyio_1.14.0 preprocessCore_1.8.0
>
>
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the Bioconductor
mailing list