edgeR: cpm() behavior appears to depend on whether edgeR is exported into the namespace. Is this normal?
2
0
Entering edit mode
@bharathananth-10049
Last seen 5.8 years ago

Hi

  I am using edgeR in an R package and as per suggested by the R programming conventions I have edgeR as a dependent package in my DESCRIPTION file and access all necessary functions using '::' without explicitly importing the package.

I noticed that at least one function (in this case cpm()) performs differently for the edgeR::cpm() and the explicity imported library(edgeR) followed by cpm(). For example,.....


> counts <- matrix(runif(100),nrow=10)
> edgeR::cpm(counts)
Error in UseMethod("cpm") :
  no applicable method for 'cpm' applied to an object of class "c('matrix', 'double', 'numeric')"

> library(edgeR)
Loading required package: limma
> head(cpm(counts))
          [,1]      [,2]      [,3]       [,4]      [,5]       [,6]      [,7]
[1,] 114169.46 175834.67  51510.14   5363.237  16401.74  20479.495 145975.39
[2,]  17889.77 205688.98  48416.19 173692.384  76566.96 105343.698 117467.74
[3,]  87684.26  40121.46  77551.01  10736.874  30670.39 158437.246  79489.89
[4,] 132548.07  64048.08 209063.65 155286.875  56091.63  95910.305 160060.34
[5,] 137226.54 132122.98  41612.64  35344.474 178261.47 144418.546 116470.77
[6,]  85941.99  17211.45  89683.65  68780.111 102690.63   5998.291  20945.59
          [,8]      [,9]     [,10]
[1,]  67399.30 131078.05  21695.84
[2,]  87848.82 154380.04 143763.65
[3,]  70340.30 132632.08  70341.64
[4,] 175579.99 109640.29 156180.73
[5,]  22645.61  78318.51 154752.79
[6,] 188434.65 122780.09 133685.27

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] edgeR_3.12.0         limma_3.26.9         BiocInstaller_1.20.1

loaded via a namespace (and not attached):
[1] tools_3.2.2


Is this expected behavior or a quirk in edgeR?

Thanks,

Bharath

edgeR namespace • 1.4k views
ADD COMMENT
2
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 10 hours ago
The city by the bay

It's because of S3 method dispatch - in your case, cpm calls cpm.default as the argument is a matrix, not a DGEList. However, the latter is not exported to the global environment, so it doesn't get found - hence the error. As you've observed, the fix is simple, and that's to load edgeR (or, call edgeR::cpm.default explicitly).

In terms of the bigger picture, it has occurred to me in the past that you could subvert edgeR's internal operations by overwriting the S3 methods in the global environment. I think Andy is working on overhauling the object orientation in edgeR, but that probably won't be finished any time soon (i.e., not before the next release).

Edit: It seems the error has more to do with the lack of S3 method registration, rather than a failure to export when using the :: operator; thanks to Gordon for pointing this out.

ADD COMMENT
0
Entering edit mode

Thanks for your clarification.

ADD REPLY
1
Entering edit mode
@gordon-smyth
Last seen 4 hours ago
WEHI, Melbourne, Australia

Thanks for pointing this out. It was an edgeR bug: the default method for cpm was not registered in the NAMESPACE. I have fixed this now in edgeR 3.12.1.

ADD COMMENT

Login before adding your answer.

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