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

<p><a href="http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata" rel="nofollow noreferrer">http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata</a></p>

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

CC BY-SA 3.0
2017-12-22T20:45:10.637Z
2017-12-22T20:45:10.637Z
Nikita Vlasenko
<p>I want to save a sparse and very large <code>dgcMatrix</code> onto disc. I read that it could be done with <code>writeMM</code> method. So, when I am trying to do that:</p>

<pre><code>writeMM(UMI_count, "/home/gene_count_filtered/filtered_dataset")
</code></pre>

<p><code>Rstudio</code> is giving me an error:</p>

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

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

<pre><code>library(Matrix)
</code></pre>

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

<pre><code>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
</code></pre>

<p>I also tried just<code>write.matrix(UMI_count, "/home/nikita/filtered_dataset")</code>, but got an error:</p>

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

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

CC BY-SA 3.0
2017-12-20T22:13:35.083Z
Which commands did you use to install Matrix? Did you use a fresh (with no environment)  session?
llrs
CC BY-SA 3.0
2017-12-20T22:43:27.413Z
Nope, but I am having this object and I need to save it. I do not want to restart 10h calculation
Nikita Vlasenko
CC BY-SA 3.0
2017-12-21T00:05:52.317Z
you can install the package in a new instance of R
llrs
CC BY-SA 3.0
2017-12-21T00:17:38.390Z
But how am I going to save the matrix of the current session? That is the issue
Nikita Vlasenko
CC BY-SA 3.0
2017-12-21T08:16:04.497Z
You open in terminal or from the menu another R session. From there you install the library, then go back to the terminal where you have the data, and try to save. If you find any problem, report the *whole* commands and output here.
llrs
CC BY-SA 3.0
2017-12-21T14:26:11.267Z
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).
Konrad Rudolph
CC BY-SA 3.0
2017-12-21T15:17:44.070Z
I was skeptical about it but restarting fixed everything.
Nikita Vlasenko
<rna-seq><r>
R: 'Matrix' can not be unloaded, but 'writeMM' method not found
# R: 'Matrix' can not be unloaded, but 'writeMM' method not found

(Asked by: username_0 on 2017-12-20)

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:
library(Matrix)

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.

**Tags:** rna-seq, r
> **Comments:**
> **username_1**: Which commands did you use to install Matrix? Did you use a fresh (with no environment)  session?  
> **username_0**: Nope, but I am having this object and I need to save it. I do not want to restart 10h calculation  
> **username_1**: you can install the package in a new instance of R  
> **username_0**: But how am I going to save the matrix of the current session? That is the issue  
> **username_1**: You open in terminal or from the menu another R session. From there you install the library, then go back to the terminal where you have the data, and try to save. If you find any problem, report the *whole* commands and output here.  
> **username_2**: 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).  
> **username_0**: I was skeptical about it but restarting fixed everything.  

---

## 1 answers

### Answer by username_0 on 2017-12-22. Score: 1 | Accepted answer

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:

<http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata>

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.


---

