4

I'm using an Rmd notebook in RStudio and have attempted to set global options at the beginning of the document. I'm trying to suppress messages and warnings. I'm getting behavior in the inline source tab that is not what I expect. It behaves as expected (no warnings, code, or messages) in the html document produced. I'm looking for it to suppress messages and warnings both inline and in the produced html output.

Here is my global chunk:

```{r global options, include = FALSE}
knitr::opts_chunk$set(echo=FALSE, include = FALSE, warning=FALSE, message=FALSE)
```

Here is a chunk that loads libraries and the output from that:

```{r load libraries}
library(tidyverse)
library(gmodels)
library(readr)
library(lubridate)
library(questionr)
```
# ── Attaching packages ───────────────────────────────────────────── tidyverse 1.2.1 ──
# ✔ ggplot2 2.2.1     ✔ 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()

# Attaching package: ‘lubridate’
# The following object is masked from ‘package:base’:
#     date

Perhaps I don't fully understand what I'm seeing but this sure looks like a message to me. Why isn't it being suppressed during execution?

Thanks.in the

kath
  • 7,624
  • 17
  • 32
Jeff Jarvis
  • 85
  • 1
  • 8
  • Add `include=FALSE` to get rid of those messages. Also, chunk labels should not have spaces. Use `-` or `_` instead. – eipi10 May 11 '18 at 21:18
  • Did you mean to say chunk labels should _not_ include spaces? Is this a style thing or a code execution thing? – Jeff Jarvis May 11 '18 at 21:20
  • Are you saying to add `include=FALSE` in each code chunk? I thought the point of the global options was so I wouldn't have to include that in each subsequent chunks. It is in my global options chunk. Thanks. – Jeff Jarvis May 11 '18 at 21:21
  • 1
    Yes "should not have." I've fixed it. [Yihui recommends avoiding spaces in chunk labels](https://yihui.name/knitr/options/) to avoid potential errors when knitting to PDF. – eipi10 May 11 '18 at 21:23
  • this is not reproducible for me, you have include=false in your global options but are saying that you still see output from other chunks? message = false should be good enough – rawr May 11 '18 at 21:25
  • Yes, that's exactly what is happening. Despite `include=FALSE`, `message=FALSE`, `warning=FALSE`, and `echo=FALSE` in the global settings, I'm still getting warnings and messages in my inline execution. It does not appear in the html output when I preview, however. – Jeff Jarvis May 11 '18 at 21:29
  • I didn't notice the `include=FALSE`. Setting that as a global option will suppress all chunk output. I actually can't reproduce your issue. With a global `message=FALSE` I don't get any package startup messages in the output document when I run your code. But yes, you will see these messages in the "R Markdown" tab of the output window. – eipi10 May 11 '18 at 21:32
  • 1
    If you want to prevent the startup messages from being printed to the "R Markdown" tab when knitting, you can do this to load the packages: `invisible(lapply(c("tidyverse","gmodels","readr","lubridate","questionr"), function(x) suppressPackageStartupMessages(require(x, character.only=TRUE))))` – eipi10 May 11 '18 at 21:43
  • This may be an issue of me just not understanding the basic functionality of R markdown. Seeing the warnings and messages in the inline execution is just mildly annoying, made worse because I couldn't understand why my global options weren't doing what I expected. So... those global options don't apply to the inline code in the "R markdown" tab, just the generated output? Thanks. – Jeff Jarvis May 11 '18 at 21:47
  • 1
    Yes, the chunk options are there to control what happens in the output document. The "R Markdown" tab in the output panel just shows the progress of the knitting operation. – eipi10 May 11 '18 at 21:58
  • Thanks! Knowing that's the functionality eases my annoyance greatly! :) – Jeff Jarvis May 11 '18 at 22:20

0 Answers0