[Bioc-devel] My "==" method breaks existing "==" method for signature c("Rle", "vector')

Martin Morgan mtmorgan at fhcrc.org
Mon May 26 18:44:04 CEST 2014


On 05/25/2014 09:39 PM, Peter Hickey wrote:
> The "==" method that I have defined for my class, MTuples, is breaking the "==" method for signature c("Rle", "vector"). I discovered this when working on something quite unrelated, namely, I couldn't resize IRanges with "fixed = end" when my package was loaded. The attached code highlights the initial problem.
>
> The error message and traceback were a little hairy - could someone please help me figure out what's going wrong?
>

I don't have an immediate answer. A work-around is to define the method on the 
group generic 'Ops' rather than '==', though maybe the generalization of 
.MTuples.compare to other members of the Ops family is not easy?

setMethod("Ops", c("MTuples", "MTuples"), function(e1, e2) TRUE)

Martin

> Thanks,
> Pete
>
> ------------------------------------------------------------------------------------------------------------------
> # Mimics the initial problem
> # Fresh R session
> library(IRanges)
> ir <- IRanges(start = 11, end = rep.int(20, 5))
>
>   # Works when repeatedly called
> resize(ir, 1, 'end') # Works
> resize(ir, 1, 'end') # Works
>
> # The method definition that breaks things
> # I haven't included the MTuples class definition or the .MTuples.compare function
> # But that shouldn't matter in order to highlight the problem, should it?
> setMethod("==", c("MTuples", "MTuples"), function(e1, e2) {
>    .MTuples.compare(e1, e2) == 0L
> })
>
> # No longer works
> resize(ir, 1, 'end')
> ------------------------------------------------------------------------------------------------------------------
>
>
> I managed to simplify the reproducible example to the following, but I can't figure out what's going wrong:
> ------------------------------------------------------------------------------------------------------------------
> # A simplified example
> # Fresh R session
> library(IRanges)
> fix <- Rle('end', 10)
>
> # Works when repeatedly called
> fix == 'end' # Works
> fix == 'end' # Works
>
> # The method definition that breaks things
> # I haven't included the MTuples class definition or the .MTuples.compare function
> # But that shouldn't matter in order to highlight the problem, should it?
> setMethod("==", c("MTuples", "MTuples"), function(e1, e2) {
>    .MTuples.compare(e1, e2) == 0L
> })
>
> # Works the first time, but not the second
> fix == 'end' # Works
> fix == 'end' # Breaks
> ------------------------------------------------------------------------------------------------------------------
>
> The same problem occurs if the vector is numeric and not character, e.g. using 7 instead of 'end'.
>
> When this breaks I get the error:
> ------------------------------------------------------------------------------------------------------------------
> Error in Rle(values = callGeneric(runValue(e1)[which1], runValue(e2)[which2]),  :
>    error in evaluating the argument 'values' in selecting a method for function 'Rle': Error in as.character(call[[1L]]) :
>    cannot coerce type 'builtin' to vector of type 'character'
> ------------------------------------------------------------------------------------------------------------------
>
> My session info is:
> ------------------------------------------------------------------------------------------------------------------
> R version 3.1.0 (2014-04-10)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
>
> attached base packages:
> [1] parallel  stats     graphics  grDevices utils     datasets  methods
> [8] base
>
> other attached packages:
> [1] IRanges_1.22.7      BiocGenerics_0.10.0
>
> loaded via a namespace (and not attached):
> [1] stats4_3.1.0
> ------------------------------------------------------------------------------------------------------------------
>
>
> --------------------------------
> Peter Hickey,
> PhD Student/Research Assistant,
> Bioinformatics Division,
> Walter and Eliza Hall Institute of Medical Research,
> 1G Royal Parade, Parkville, Vic 3052, Australia.
> Ph: +613 9345 2324
>
> hickey at wehi.edu.au
> http://www.wehi.edu.au
>
>
> ______________________________________________________________________
> The information in this email is confidential and inte...{{dropped:16}}



More information about the Bioc-devel mailing list