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()
.