IRanges: as.matrix.RangesMatching not found with NAMESPACE
1
0
Entering edit mode
@michael-dondrup-3849
Last seen 10.2 years ago
Hi, I made a package depending on IRanges. When I try to use as.matrix on a RangesMatching object, there is an error message, if I don't have a NAMESPACE or I just source the file it works. Am I doing something wrong? I made a reproducible example, used package skeleton to build the package for this. The whole test -package is available at: http://www.bccs.uni.no/~mdo041/anRpackage/ #require (IRanges) doit <- function() { query <- IRanges(c(1, 4, 9), c(5, 7, 10)) subject <- IRanges(c(2, 2, 10), c(2, 3, 12)) tree <- IntervalTree(subject) ## check if it works? ol = findOverlaps(query, tree, multiple = TRUE) # c(2, NA, 3) print (ol) print (typeof(ol)) as.matrix(ol) } NAMESPACE: exportPattern("^[[:alpha:]]+") Here is the output: > library(anRpackage) Loading required package: IRanges Attaching package: 'IRanges' The following object(s) are masked from package:base : Map, cbind, mapply, order, pmax, pmax.int, pmin, pmin.int, rbind, rep.int, table > doit() An object of class "RangesMatching" Slot "matchMatrix": query subject [1,] 1 2 [2,] 1 1 [3,] 3 3 Slot "DIM": [1] 3 3 [1] "S4" Error in as.vector(data) : no method for coercing this S4 class to a vector And that is the output when there is no NAMESPACE > library(anRpackage) Loading required package: IRanges Attaching package: 'IRanges' The following object(s) are masked from package:base : Map, cbind, mapply, order, pmax, pmax.int, pmin, pmin.int, rbind, rep.int, table > doit() An object of class "RangesMatching" Slot "matchMatrix": query subject [1,] 1 2 [2,] 1 1 [3,] 3 3 Slot "DIM": [1] 3 3 [1] "S4" query subject [1,] 1 2 [2,] 1 1 [3,] 3 3 > > sessionInfo() R version 2.10.1 (2009-12-14) x86_64-apple-darwin9.8.0 locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] anRpackage_1.0 IRanges_1.4.16 loaded via a namespace (and not attached): [1] tools_2.10.1 > Best Michael Dondrup Post-doctoral researcher Uni BCCS Thorm?hlensgate 55, N-5008 Bergen, Norway
IRanges IRanges • 1.7k views
ADD COMMENT
0
Entering edit mode
Patrick Aboyoun ★ 1.6k
@patrick-aboyoun-6734
Last seen 10.2 years ago
United States
Michael, The answer is in the Writing R Extensions manual: http://cran.r-project.org/doc/manuals/R-exts.html#Package-name-spaces "Note that adding a name space to a package changes the search strategy. The package name space comes first in the search, then the imports, then the base name space and then the normal search path." Since the (S3) generic for as.matrix is in the base package it is retrieved instead of the implicit S4 generic that is defined in IRanges. The solution to this problem is to make IRanges and Imports in the DESCRIPTION file and add import(IRanges) to the NAMESPACE file. Patrick On 3/25/10 7:03 AM, Michael Dondrup wrote: > Hi, > > I made a package depending on IRanges. When I try to use as.matrix on a RangesMatching object, > there is an error message, if I don't have a NAMESPACE or I just source the file it works. Am I doing something wrong? > I made a reproducible example, used package skeleton to build the package for this. > The whole test -package is available at: > > http://www.bccs.uni.no/~mdo041/anRpackage/ > > > #require (IRanges) > > doit<- function() { > query<- IRanges(c(1, 4, 9), c(5, 7, 10)) > subject<- IRanges(c(2, 2, 10), c(2, 3, 12)) > tree<- IntervalTree(subject) > > ## check if it works? > ol = findOverlaps(query, tree, multiple = TRUE) # c(2, NA, 3) > print (ol) > print (typeof(ol)) > as.matrix(ol) > } > > NAMESPACE: > exportPattern("^[[:alpha:]]+") > > > > Here is the output: > > > >> library(anRpackage) >> > Loading required package: IRanges > > Attaching package: 'IRanges' > > > The following object(s) are masked from package:base : > > Map, > cbind, > mapply, > order, > pmax, > pmax.int, > pmin, > pmin.int, > rbind, > rep.int, > table > > >> doit() >> > An object of class "RangesMatching" > Slot "matchMatrix": > query subject > [1,] 1 2 > [2,] 1 1 > [3,] 3 3 > > Slot "DIM": > [1] 3 3 > > [1] "S4" > Error in as.vector(data) : > no method for coercing this S4 class to a vector > > > And that is the output when there is no NAMESPACE > > >> library(anRpackage) >> > Loading required package: IRanges > > Attaching package: 'IRanges' > > > The following object(s) are masked from package:base : > > Map, > cbind, > mapply, > order, > pmax, > pmax.int, > pmin, > pmin.int, > rbind, > rep.int, > table > > >> doit() >> > An object of class "RangesMatching" > Slot "matchMatrix": > query subject > [1,] 1 2 > [2,] 1 1 > [3,] 3 3 > > Slot "DIM": > [1] 3 3 > > [1] "S4" > query subject > [1,] 1 2 > [2,] 1 1 > [3,] 3 3 > >> > > >> sessionInfo() >> > R version 2.10.1 (2009-12-14) > x86_64-apple-darwin9.8.0 > > locale: > [1] C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] anRpackage_1.0 IRanges_1.4.16 > > loaded via a namespace (and not attached): > [1] tools_2.10.1 > >> > > Best > > > > Michael Dondrup > Post-doctoral researcher > Uni BCCS > Thorm?hlensgate 55, N-5008 Bergen, Norway > > _______________________________________________ > 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
Patrick, thank you very much! I find it amazing how helpful the IRanges authors (and BioC in general) are with any kind of question or problem. Even though I could have figured it out myself, had I just read the documentation on namespaces more carefully. Just wanted to say this this is great. I added "import(IRanges)" to my NAMESPACE file and it works. Best Michael Am Mar 25, 2010 um 5:32 PM schrieb Patrick Aboyoun: > Michael, > The answer is in the Writing R Extensions manual: > > http://cran.r-project.org/doc/manuals/R-exts.html#Package-name- spaces > > "Note that adding a name space to a package changes the search strategy. The package name space comes first in the search, then the imports, then the base name space and then the normal search path." > > Since the (S3) generic for as.matrix is in the base package it is retrieved instead of the implicit S4 generic that is defined in IRanges. The solution to this problem is to make IRanges and Imports in the DESCRIPTION file and add import(IRanges) to the NAMESPACE file. > > > Patrick > > > > On 3/25/10 7:03 AM, Michael Dondrup wrote: >> Hi, >> >> I made a package depending on IRanges. When I try to use as.matrix on a RangesMatching object, >> there is an error message, if I don't have a NAMESPACE or I just source the file it works. Am I doing something wrong? >> I made a reproducible example, used package skeleton to build the package for this. >> The whole test -package is available at: >> >> http://www.bccs.uni.no/~mdo041/anRpackage/ >> >> >> #require (IRanges) >> >> doit<- function() { >> query<- IRanges(c(1, 4, 9), c(5, 7, 10)) >> subject<- IRanges(c(2, 2, 10), c(2, 3, 12)) >> tree<- IntervalTree(subject) >> >> ## check if it works? >> ol = findOverlaps(query, tree, multiple = TRUE) # c(2, NA, 3) >> print (ol) >> print (typeof(ol)) >> as.matrix(ol) >> } >> >> NAMESPACE: >> exportPattern("^[[:alpha:]]+") >> >> >> >> Here is the output: >> >> >> >>> library(anRpackage) >>> >> Loading required package: IRanges >> >> Attaching package: 'IRanges' >> >> >> The following object(s) are masked from package:base : >> >> Map, >> cbind, >> mapply, >> order, >> pmax, >> pmax.int, >> pmin, >> pmin.int, >> rbind, >> rep.int, >> table >> >> >>> doit() >>> >> An object of class "RangesMatching" >> Slot "matchMatrix": >> query subject >> [1,] 1 2 >> [2,] 1 1 >> [3,] 3 3 >> >> Slot "DIM": >> [1] 3 3 >> >> [1] "S4" >> Error in as.vector(data) : >> no method for coercing this S4 class to a vector >> >> >> And that is the output when there is no NAMESPACE >> >> >>> library(anRpackage) >>> >> Loading required package: IRanges >> >> Attaching package: 'IRanges' >> >> >> The following object(s) are masked from package:base : >> >> Map, >> cbind, >> mapply, >> order, >> pmax, >> pmax.int, >> pmin, >> pmin.int, >> rbind, >> rep.int, >> table >> >> >>> doit() >>> >> An object of class "RangesMatching" >> Slot "matchMatrix": >> query subject >> [1,] 1 2 >> [2,] 1 1 >> [3,] 3 3 >> >> Slot "DIM": >> [1] 3 3 >> >> [1] "S4" >> query subject >> [1,] 1 2 >> [2,] 1 1 >> [3,] 3 3 >> >>> >> >> >>> sessionInfo() >>> >> R version 2.10.1 (2009-12-14) >> x86_64-apple-darwin9.8.0 >> >> locale: >> [1] C >> >> attached base packages: >> [1] stats graphics grDevices utils datasets methods base >> >> other attached packages: >> [1] anRpackage_1.0 IRanges_1.4.16 >> >> loaded via a namespace (and not attached): >> [1] tools_2.10.1 >> >>> >> >> Best >> >> >> >> Michael Dondrup >> Post-doctoral researcher >> Uni BCCS >> Thorm?hlensgate 55, N-5008 Bergen, Norway >> >> _______________________________________________ >> 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 >> > > _______________________________________________ > 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 REPLY

Login before adding your answer.

Traffic: 968 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