Description
Dear developers!
We have some randomly occurring errors in the MSnbase
package (see issue lgatto/MSnbase#151) that I believe are somehow related with the Rcpp
package. First, what makes me believe this is a memory problem is that a) it occurs randomly and b) it can be solved by a call to gc()
. Why I believe it's related to Rcpp
: in MSnbase
we use facilities from Bioconductor's mzR
package (https://github.com/sneumann/mzR) to read files. mzR
uses routines implemented in C++ to read these files.
Based on how the errors are happening I have the feeling that memory is not cleaned up properly after calling the C++ functions.
In the example below we read the header of a file and create some objects after that. Note that the errors do not appear without the calls to new
. Also, calling gc()
after each rm(msd)
fixes the problem.
library(MSnbase)
library(msdata)
f <- system.file("microtofq/MM8.mzML", package = "msdata")
for (i in 1:5000) {
if (i %% 200 == 0)
cat(i, "\n")
## open the file.
msd <- mzR::openMSfile(f)
fullHead <- mzR::header(msd)
mzR::close(msd)
rm(msd)
## Process
process <- new("MSnProcess",
processing = paste0("Data loaded [", date(), "]"),
files = f,
smoothed = NA)
## pdata
.pd <- data.frame(sampleNames = basename(f))
rownames(.pd) <- .pd$sampleNames
pdata <- new("NAnnotatedDataFrame",
data = .pd)
}
Error in (function (x) : attempt to apply non-function
Error in (function (x) : attempt to apply non-function
Error in (function (x) : attempt to apply non-function
Error in (function (x) : attempt to apply non-function
Error in (function (x) : attempt to apply non-function
I would be grateful for any hints how to solve this differently to calling gc
after each import.
All packages used are from Bioconductor, so you could grap them using
source("http://www.bioconductor.org/biocLite.R")
biocLite(c("MSnbase", "mzR", "msdata"))
My sessionInfo
:
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin15.6.0/x86_64 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] msdata_0.12.0 MSnbase_1.21.8 ProtGenerics_1.4.0
[4] BiocParallel_1.6.3 mzR_2.6.3 Rcpp_0.12.6
[7] Biobase_2.32.0 BiocGenerics_0.18.0
loaded via a namespace (and not attached):
[1] magrittr_1.5 IRanges_2.6.1 zlibbioc_1.18.0
[4] doParallel_1.0.10 munsell_0.4.3 colorspace_1.2-6
[7] impute_1.46.0 lattice_0.20-33 foreach_1.4.3
[10] stringr_1.0.0 plyr_1.8.4 tools_3.3.1
[13] mzID_1.10.2 grid_3.3.1 gtable_0.2.0
[16] affy_1.50.0 iterators_1.0.8 digest_0.6.9
[19] preprocessCore_1.34.0 affyio_1.42.0 reshape2_1.4.1
[22] ggplot2_2.1.0 S4Vectors_0.10.2 codetools_0.2-14
[25] MALDIquant_1.15 limma_3.28.16 stringi_1.1.1
[28] BiocInstaller_1.22.3 pcaMethods_1.64.0 scales_0.4.0
[31] XML_3.98-1.4 stats4_3.3.1 vsn_3.40.0