Closed karasovolson closed 6 years ago
You could try using the chunk option include = FALSE
for the chunk where you load all your packages, that might do the trick.
Hi @karasovolson! So there are a few different categories of messages that R will spit out. Some are the package startup messages (like when we load tidyverse....see below):
>library(tidyverse)
── Attaching packages ────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 2.2.1.9000 ✔ purrr 0.2.4
✔ tibble 1.4.2 ✔ dplyr 0.7.4
✔ tidyr 0.8.0 ✔ stringr 1.3.0
✔ readr 1.1.1 ✔ forcats 0.3.0
── Conflicts ───────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
✖ dplyr::n() masks .env::n()
Other messages are warnings which tell us things like our package versions don't match up with the current version of R (but updating will generally fix this). Typically, things will still run with warning messages.
Errors however, the other last type of message, and these occur when something doesn't run. Some are more useful than others.
One thing you can add to your Rmd R chunk is either the warning=FALSE
or error=FALSE
, which will effectively mute those messages when you knit your Rmd file. Be aware if you use error=FALSE
, you may not know why things aren't running if something breaks. :)
Here's an example r chunk which shows the code (echo=TRUE) and sets the above things to false:
{r echo=TRUE, warning=FALSE, error=FALSE}
library(tidyverse)
Hope this helps! You can certainly use include=FALSE
to not include the code output (aside from figures). But using combinations of the above options may be useful as well! 👍 🚀
There's also a message=
argument that you can pass to each chunk.
So the code will run and just the code (with no output) will be printed when you build a chunk like this:
``` {r warning = FALSE, error = FALSE, message= FALSE} library(tidyverse) ```
This is a way to reduce the clutter of the output in the final document without needing the suppressPackageStartupMessages()
function.
Thanks everyone! warning = FALSE fixed the problem as did updating my version of R.
@ryanpeek , when I use this function, it suppresses most of the startup messages, but a few warnings still pop up. The ones that still appear in my knitted file are warnings that certain packages (tidyverse, tibble, dplyr, etc) were built under various versions of R. Do you know why these messages still appear? Is there a way to get rid of them too?