Skip to content
Prev 14327 / 21312 Next

[Bioc-devel] Error : object 'lengths' is not exported by 'namespace:BiocGenerics'

I'm going to try to provide some details, at the risk to confuse you even more.


In BioC 3.8 / R 3.5 base::lengths() was not just slow on some Bioconductor objects like IRanges or GRanges, it didn't work:


  > ir <- IRanges(1:21, 20)
  > base::lengths(ir)
  Error in getListElement(x, i, ...) :
    IRanges objects don't support [[, as.list(), lapply(), or unlist() at
    the moment


Now it works (in BioC 3.9 / R 3.6):


  > ir <- IRanges(1:21, 20)
  > base::lengths(ir)
   [1] 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0


The change I announced in my original post is about base::lengths() being now an S4 generic. A standard S4 generic like BiocGenerics::lengths() or base::lengths() doesn't do any work beyond dispatching to the right method. What happened in R 3.6 is that base::lengths() is now an S4 generic. This means that it knows how to take care of dispatching to the right method. The various "lengths" methods defined in Bioconductor are the ones doing the real work and they are fast. They have not changed and their speed should not be affected by this change in base::lengths().


Furthermore: in R 3.6, even though you can't see it, there is a default "lengths" method defined in base (it's used as a fallback when no other method applies). In my 1st code chunk above (i.e. when base::lengths() was not a generic), I'm calling directly this default method (note that this was the default method of the BiocGenerics::lengths() generic). This default method is indeed slow or doesn't work on Bioconductor objects. By calling BiocGenerics::lengths() (in BioC 3.8) or base::lengths() (in BioC 3.9), dispatch selects the fast method so nothing has changed from that perspective.


Hope this helps,

H.
On 11/13/18 08:59, H?kon Tjeldnes wrote:
Just to be sure, you are saying that now base::lengths is as fast as BiocGenerics::lengths was ? Else we would still need the Bioc version. Because the old base implementation was terrible, I will try to verify this if you are unsure.
________________________________
Fra: Michael Lawrence <lawrence.michael at gene.com><mailto:lawrence.michael at gene.com>
Sendt: fredag 2. november 2018 23.50
Til: hauken_heyken at hotmail.com<mailto:hauken_heyken at hotmail.com>
Kopi: bioc-devel; Herv? Pag?s
Emne: Re: [Bioc-devel] Error : object 'lengths' is not exported by 'namespace:BiocGenerics'

Yes, please follow Herv?'s instructions.
On Fri, Nov 2, 2018 at 3:41 PM H?kon Tjeldnes <hauken_heyken at hotmail.com<mailto:hauken_heyken at hotmail.com>> wrote:
Just a quick question, in 3.8 we used biogenerics::lengths for ORFik, since it was much faster than base, for our dataset 1 second vs 30 minutes. We should change to S4 version of lengths now ?

Get Outlook for Android<https://aka.ms/ghei36<https://urldefense.proofpoint.com/v2/url?u=https-3A__eur02.safelinks.protection.outlook.com_-3Furl-3Dhttps-253A-252F-252Faka.ms-252Fghei36-26data-3D02-257C01-257C-257Ce617c34c45584b70cf7008d6411590f9-257C84df9e7fe9f640afb435aaaaaaaaaaaa-257C1-257C0-257C636767958210704172-26sdata-3DUl3jkwHfZdrwQjkzzBQTKrXdQ5NXQ1vWRrx7vojZEAw-253D-26reserved-3D0&d=DwMFAw&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=VkR31AqDi_FLujiTJm39v-jaLNkPJov4_ZlFjFit9UI&s=C8hC46CIc0bUw9WUxrvaekaCsN1NAlLcyxiuFKgRjCs&e=>>