5

I love using the readxl package. However, I've been using it as part of an RMarkdown document and some of the read_excel() message when reading in files are useful when doing analysis but not when trying to present the analysis. So the question is, is there any way to suppress the message received (or any warning message for that matter) when using read_excel? I'll take an RMarkdown OR read_excel solution.

Here is an illustration of the type of message I'd like to suppress. The appears in my final Rmarkdown document:

## Parsed with column specification:
## cols(
##   .default = col_character(),
##   Year = col_integer(),
##   Month = col_integer(),
##   Date = col_date(format = ""),
##   Day = col_integer(),
##   Replicate = col_integer(),
##   Time = col_integer(),
##   Depth = col_double(),
##   DenTotal = col_integer()
## )
## See spec(...) for full column specifications.

I haven't been able to find a way to read in an excel file from a url using read_excel so I'm not able to make a reproducible example here.

Cœur
  • 37,241
  • 25
  • 195
  • 267
boshek
  • 4,100
  • 1
  • 31
  • 55
  • Maybe `suppressMessages` depending on how the package prints output. – lmo Dec 19 '16 at 17:27
  • You can wrap the call in `invisible` or you can set your `knitr` options for `messages` and `warnings` to what you would like. – Jake Kaupp Dec 19 '16 at 17:30
  • 1
    `suppressMessage()` worked, `invisible()` did not and nor did `{r chunk1, echo=FALSE, warning=FALSE}`. – boshek Dec 19 '16 at 17:38
  • @lmo if you wanted to put that as an answer I can accept it. – boshek Dec 19 '16 at 17:39
  • 2
    Does setting the `message = FALSE` suppress the message? I'm honestly surprised that `invisible` doesn't handle it. – Jake Kaupp Dec 19 '16 at 17:48
  • Yeah neither worked. I was surprised too. – boshek Dec 19 '16 at 17:59
  • 1
    Setting `warning = FALSE` as a chunk option will suppress warnings... use `message = FALSE` to suppress messages (or use the hammer of `include = FALSE` to suppress *everything*). – Gregor Thomas Dec 19 '16 at 19:31

1 Answers1

3

If the package prints out messages using the message function, then the suppressMessages should work to prevent the messages from printing. From the help file, ?suppressMessages,

evaluates its expression in a context that ignores all ‘simple’ diagnostic messages.

lmo
  • 37,904
  • 9
  • 56
  • 69