18

I am creating a rmarkdown pdf report. I used read_csv function from readr package to import some csv files in a folder. I used SuppressMessages/Warnings functions to hide all warnings/messages, but I still get the messages as below when trying to import multiple files:

It seems SuppressMessages/Warnings don't work on the parsing warnings.

## Parsed with column specification:
## cols(
## .default = col_character(),
## `Constant USD - Accrued Sum` = col_number(),
## `Units Sold Sum` = col_number()
## )

Because the report is aimed for non-technical audience, the warning messages can be a distraction. What can I do to keep this message from showing?

halfer
  • 19,824
  • 17
  • 99
  • 186
Felix Zhao
  • 459
  • 5
  • 9

3 Answers3

29

Just add col_types = cols() in the read_csv() function call

read_csv("path/to/file", col_types = cols())
Shinobi_Atobe
  • 1,793
  • 1
  • 18
  • 35
  • 1
    There is still the message saying `i Using "','" as decimal and "'.'" as grouping mark. Use read_delim() for more control.` – Julien Nov 29 '22 at 15:25
8

Add message=FALSE to the chunk header:

```{r message=FALSE}
library("readr")
test <- read_csv("example.csv")
```
Phil
  • 4,344
  • 2
  • 23
  • 33
1

Use show_col_types = FALSE to silence col type messages

This is silent:

library(readr)
df <- read_csv(readr_example("chickens.csv"), show_col_types = FALSE)

Whereas read_csv(readr_example("chickens.csv")) returns:

Rows: 5 Columns: 4                                                                                                                            
── Column specification ───────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (3): chicken, sex, motto
dbl (1): eggs_laid

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69