Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress All Messages/Warnings with Readr read_csv function

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?

like image 639
Felix Zhao Avatar asked Apr 15 '19 10:04

Felix Zhao


People also ask

How do I suppress a message in R?

suppressPackageStartupMessages() method in R language can be used to disable messages displayed upon loading a package in R. This method is used to suppress package startup messages.

What is read_csv function r?

read_csv() reads comma delimited files, read_csv2() reads semicolon separated files (common in countries where , is used as the decimal place), read_tsv() reads tab delimited files, and read_delim() reads in files with any delimiter.

What is the difference between read_csv and read CSV?

The read_csv function imports data into R as a tibble, while read. csv imports a regular old R data frame instead. Tibbles are better than regular data frames because they: load faster.


2 Answers

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

read_csv("path/to/file", col_types = cols())
like image 190
Shinobi_Atobe Avatar answered Oct 23 '22 22:10

Shinobi_Atobe


Add message=FALSE to the chunk header:

```{r message=FALSE}
library("readr")
test <- read_csv("example.csv")
```
like image 8
Phil Avatar answered Oct 23 '22 21:10

Phil