Jim Hester

The readr package makes it easy to get rectangular data out of comma separated (csv), tab separated (tsv) or fixed width files (fwf) and into R. It is designed to flexibly parse many types of data found in the wild, while still cleanly failing when data unexpectedly changes. If you are new to readr, the best place to start is the data import chapter in R for data science.

install.packages("readr")


library(tidyverse)

#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──

#> ✔ ggplot2 3.3.2     ✔ purrr   0.3.4
#> ✔ tibble  3.0.3     ✔ dplyr   1.0.2
#> ✔ tidyr   1.1.2     ✔ stringr 1.4.0
#> ✔ readr   1.4.0     ✔ forcats 0.5.0

#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──


## Breaking Changes

### Argument name consistency

The first argument to all of the write_() functions, like write_csv() had previously been path. However the first argument to all of the read_() functions is file. As of readr 1.4.0 the first argument to both read_() and write_() functions is file and path is now deprecated.

### NaN behavior

Some floating point operations can produce a NaN value, e.g. 0 / 0. Previously write_csv() would output NaN values always as NaN and this could not be controlled by the write_csv(na=) argument. Now the output value of NaN is the same as the NA and can be controlled by the argument. This is a breaking change in that the same code would produce different output, but it should be rare in practice.

## New features

### Generate column specifications from datasets

Using as.col_spec() on any data.frame or tibble object will now generate a column specification with the column types in the data.

library(palmerpenguins)
spec <- as.col_spec(penguins)
spec

#> cols(
#>   species = col_factor(levels = c("Adelie", "Chinstrap", "Gentoo"), ordered = FALSE, include_na = FALSE),
#>   island = col_factor(levels = c("Biscoe", "Dream", "Torgersen"), ordered = FALSE, include_na = FALSE),
#>   bill_length_mm = col_double(),
#>   bill_depth_mm = col_double(),
#>   flipper_length_mm = col_integer(),
#>   body_mass_g = col_integer(),
#>   sex = col_factor(levels = c("female", "male"), ordered = FALSE, include_na = FALSE),
#>   year = col_integer()
#> )


You can also convert the column specifications to a condensed textual representation with as.character()

as.character(spec)

#> [1] "ffddiifi"


### Writing end of line characters

Write functions now take a eol argument to allow control of the end of line characters. Previously readr only supported using a single newline (\n) character. You can now specify any number of characters, though windows linefeed newline (\r\n) is by far the most common alternative.

### cli package is now used for messages

The cli package is now used for messages. The most prominent place you will notice this is printing the column specifications. Previously these functions used message(), which in RStudio prints the text in red.

While cli still uses message objects, they will now be more naturally colored, which hopefully will make them easier to read.

### Rcpp dependency removed

The Rcpp dependency has been removed in favor of cpp11. Compiling readr should now take less time and use less memory.

## Acknowledgements

As usual, there were many more additional changes and bugfixes included in this release see the change log for details.

Contents