[BioC] Using annotation maps as environments in packages

Marc Carlson mcarlson at fhcrc.org
Thu Mar 4 19:42:56 CET 2010

Hi Antti,

You didn't give a lot of detail, but this message probably means that
you did not load the Annotation package before calling (in the 3rd
case). You can put a call to require() in your function to make the
specific annotation package be loaded, but this is probably NOT the best
way to handle that.  It is probably a much better idea at this point for
you to look at the getAnnMap() function from the annotate package.


As you read the manual page, you will see that getAnnMap is used to
return the map (what you are calling the envir) so that you can do this
sort of thing in a more generic way.  That is, you specify the package
name and the mapping you want, and getAnnMap will try to load any needed
packages etc. to make sure that its there for you.

Hope this helps,


On 03/04/2010 10:18 AM, 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
> 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

More information about the Bioconductor mailing list