Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Remove the output of the garbage collector gc() in Rmarkdown

$
0
0

I have a Rmarkdown document where the garbage collector is used to save memory during renderization. The function gc() is called at the end of some code chunks for convenience, but I would like to hide its output, while showing other code in the same chunk (e.g. a plot). If this output is impossible to hide without using eval=FALSE or include=FALSE (eg. with gc() in a separate chunk), then I would like to understand why, and if this might happen for other functions as well.

Example code to reproduce the problem is given below:

---
title: "Example"
output:
  html_document
---

```{r, message=FALSE, warning=FALSE, echo=FALSE}
library("tidyverse")
```


```{r, message=FALSE, warning=FALSE, echo=FALSE}
df <- mtcars %>% dplyr::group_by(cyl) %>% dplyr::summarise(meanMPG = mean(mpg))
df %>% ggplot() + geom_point(aes(x=cyl, y=meanMPG))
rm(df); gc(verbose = FALSE, full = FALSE)
```

EDIT: as you can note, the problem persist even when the options verbose=FALSE and full=FALSE are used in gc().


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>