I want to save a sparse and very large dgcMatrix onto disc. I read that it could be done with writeMM method. So, when I am trying to do that:

writeMM(UMI_count, "/home/gene_count_filtered/filtered_dataset")

Rstudio is giving me an error:

Error in writeMM(UMI_count, "/home/gene_count_filtered/filtered_dataset") : 
could not find function "writeMM"

Ok, I read that this function is in the Matrix package. I installed it, but when I try loading it:


I am getting another error due to other libraries using Matrix already on the lower level, as I understand:

Error in value[[3L]](cond) : 
Package ‘Matrix’ version 1.2.11 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘Matrix’ is imported by 
‘scran’, ‘scater’, ‘SummarizedExperiment’ so cannot be unloaded

I also tried justwrite.matrix(UMI_count, "/home/nikita/filtered_dataset"), but got an error:

Cholmod error 'out of memory' at file ../Core/cholmod_memory.c, line 147

What could be the solution to the problem? I just need to somehow save a very large dgcMatrix on disc.

  • $\begingroup$ Which commands did you use to install Matrix? Did you use a fresh (with no environment) session? $\endgroup$
    – llrs
    Dec 20 '17 at 22:13
  • $\begingroup$ Nope, but I am having this object and I need to save it. I do not want to restart 10h calculation $\endgroup$ Dec 20 '17 at 22:43
  • $\begingroup$ you can install the package in a new instance of R $\endgroup$
    – llrs
    Dec 21 '17 at 0:05
  • $\begingroup$ But how am I going to save the matrix of the current session? That is the issue $\endgroup$ Dec 21 '17 at 0:17
  • 1
    $\begingroup$ Restarting R should fix this. There’s probably no way around this (you could try to manually unload all namespaces that use the Matrix package). $\endgroup$ Dec 21 '17 at 14:26

Ultimately I just restarted Rstudio as Konrad Rudolph suggested, imported Matrix library, and then writeMM method worked just fine. However, rownames were converted into just numbers, but I needed to keep the gene names instead as it was in dgcMatrix, so after some search I found a different way of doing that from here:


So, I just did save() (and then, to load back - load()) and the rownames are maintained like I wanted it to be. So, storing it now as .RData file.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.