使用 Readr read_csv 函数抑制所有消息/警告

Fel*_*hao 11 markdown r suppress-warnings suppressmessage readr

我正在创建一个 rmarkdown pdf 报告。我使用 readr 包中的 read_csv 函数在文件夹中导入一些 csv 文件。我使用 SuppressMessages/Warnings 函数来隐藏所有警告/消息,但在尝试导入多个文件时仍然收到如下消息:

似乎 SuppressMessages/Warnings 对解析警告不起作用。

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

由于该报告面向非技术受众,因此警告信息可能会分散注意力。我该怎么做才能不显示此消息?

Shi*_*obe 24

只需col_types = cols()read_csv()函数调用中添加

read_csv("path/to/file", col_types = cols())
Run Code Online (Sandbox Code Playgroud)


Phi*_*hil 7

添加message=FALSE到块头:

```{r message=FALSE}
library("readr")
test <- read_csv("example.csv")
```
Run Code Online (Sandbox Code Playgroud)


Ric*_*loo 5

用于show_col_types = FALSE静音 col 类型消息

\n

这是沉默的:

\n
library(readr)\ndf <- read_csv(readr_example("chickens.csv"), show_col_types = FALSE)\n
Run Code Online (Sandbox Code Playgroud)\n

read_csv(readr_example("chickens.csv"))返回:

\n
Rows: 5 Columns: 4                                                                                                                            \n\xe2\x94\x80\xe2\x94\x80 Column specification \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\nDelimiter: ","\nchr (3): chicken, sex, motto\ndbl (1): eggs_laid\n\n\xe2\x84\xb9 Use `spec()` to retrieve the full column specification for this data.\n\xe2\x84\xb9 Specify the column types or set `show_col_types = FALSE` to quiet this message.\n
Run Code Online (Sandbox Code Playgroud)\n