Skip to content

Suppress messages in read_csv #954

Closed
@bovender

Description

@bovender

Using read_csv, is it possible at all to suppress the "Parsed with column specification: ..." messages?

I have an R Markdown document that involves importing 50+ CSV files with multiple columns each, and the output gets very bloated by the 50+ "Parsed with..." blocks. I have tried to set the chunk options message and warning to false, to no avail.

Activity

jimhester

jimhester commented on Jan 10, 2019

@jimhester
Collaborator

The best solution assuming your data formats are consistent is to include the column specifications in the read calls. This will catch errors early if the data format changes.

You can copy paste the printed output directly (which is one of the intents of printing it). e.g.

library(readr)
col_types <- cols(
  mpg = col_double(),
  cyl = col_double(),
  disp = col_double(),
  hp = col_double(),
  drat = col_double(),
  wt = col_double(),
  qsec = col_double(),
  vs = col_double(),
  am = col_double(),
  gear = col_double(),
  carb = col_double()
)

filename <- readr_example("mtcars.csv")
read_csv(filename, col_types = col_types)
#> # A tibble: 32 x 11
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
#>  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
#>  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
#>  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
#>  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
#>  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
#>  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
#>  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
#>  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
#> 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
#> # ... with 22 more rows

Otherwise you can use col_types = cols() to explicitly use the default guessing behavior, which also suppresses the printing.

library(readr)
filename <- readr_example("mtcars.csv")
read_csv(filename, col_types = cols())
#> # A tibble: 32 x 11
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
#>  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
#>  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
#>  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
#>  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
#>  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
#>  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
#>  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
#>  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
#> 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
#> # ... with 22 more rows

Created on 2019-01-09 by the reprex package (v0.2.1)

jimhester

jimhester commented on Jan 10, 2019

@jimhester
Collaborator

Also the column specifications are normal R messages, so setting message = FALSE in your chunk options will suppress them. I realize you said you tried this, but I think something must have gone awry, the following Rmd file does suppress them as expected.

```{r message = FALSE}
readr::read_csv(readr::readr_example("mtcars.csv"))
```
bovender

bovender commented on Jan 10, 2019

@bovender
Author

Well this is embarassing... This morning message = FALSE does indeed suppress those messages. Maybe some issue with caching yesterday? Thank you very much indeed for your assistance!

lock

lock commented on Jul 9, 2019

@lock

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

locked and limited conversation to collaborators on Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jimhester@bovender

        Issue actions

          Suppress messages in read_csv · Issue #954 · tidyverse/readr