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
--
Antti Honkela
Antti.Honkela at tkk.fi - http://www.cis.hut.fi/ahonkela/
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.
library(annotate)
?getAnnMap
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,
Marc
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
>
>
Hi Marc,
I think there is something deeper going on in that the overloaded
"get" generic function for the ProbeAnnDbBimap class does not work the
way one would assume when called from a function inside a package.
Unfortunately my understanding of intricacies of R packages,
namespaces and generic functions does not help any further.
The suggested getAnnMap() does not solve that, as changing the
function (in the package) to
getAnnotation <- function(gene, map, chip) {
require(annotate)
env <- getAnnMap(map, chip)
show(env)
return (get(gene, env=env))
}
leads to the same result:
> getAnnotation("1419728_at", "SYMBOL", "mouse430a2")
Loading required package: annotate
Loading required package: AnnotationDbi
Loading required package: Biobase
Welcome to Bioconductor
Vignettes contain introductory material. To view, type
'openVignette()'. To cite Bioconductor, see
'citation("Biobase")' and for packages 'citation(pkgname)'.
Loading required package: org.Mm.eg.db
Loading required package: DBI
SYMBOL map for chip mouse430a2 (object of class "ProbeAnnDbBimap")
Error in get(gene, env = env) : invalid 'envir' argument
--------------------------------------------------------------------
Note the output of show(env), i.e. we are getting the correct map but
the get() call still fails.
At the same time doing the same on the command line works:
------------------------------------------------
> map <- getAnnMap("SYMBOL", "mouse430a2")
> map
SYMBOL map for chip mouse430a2 (object of class "ProbeAnnDbBimap")
> get("1419728_at", map)
[1] "Cxcl5"
------------------------------------------------
Antti
On Mar 4, 2010, at 18:42 , Marc Carlson wrote:
> 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.
>
> library(annotate)
> ?getAnnMap
>
> 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,
>
>
> Marc
>
>
>
>
> 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
>>
>>
>
> _______________________________________________
> 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
>
>
--
Antti Honkela
Antti.Honkela at tkk.fi - http://www.cis.hut.fi/ahonkela/
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
On Mar 4, 2010, at 19:51 , Hervé Pagès wrote:
Hi Herv?,
> 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).
Thanks, that solved the problem!
It might be useful if you could add a note of this to the AnnDbBimap-
envirAPI help page as well.
Antti
--
Antti Honkela
Antti.Honkela at tkk.fi - http://www.cis.hut.fi/ahonkela/