zapier/readr

Name: readr

Owner: Zapier

Description: Read flat files (csv, tsv, fwf) into R

Forked from: tidyverse/readr

Created: 2017-06-05 20:17:40.0

Updated: 2017-10-09 05:58:03.0

Pushed: 2017-05-20 13:15:22.0

Homepage: readr.tidyverse.org

Size: 2198

Language: R

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

readr

CRAN\_Status\_Badge Build Status AppVeyor Build Status Coverage Status

Overview

The goal of readr is to provide a fast and friendly way to read rectangular data (like csv, tsv, and fwf). 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.

Installation
e easiest way to get readr is to install the whole tidyverse:
all.packages("tidyverse")

ternatively, install just readr:
all.packages("readr")

 the the development version from GitHub:
stall.packages("devtools")
ools::install_github("tidyverse/readr")
Usage

readr is part of the core tidyverse, so load it with:

ary(tidyverse)
oading tidyverse: ggplot2
oading tidyverse: tibble
oading tidyverse: tidyr
oading tidyverse: readr
oading tidyverse: purrr
oading tidyverse: dplyr
onflicts with tidy packages ----------------------------------------------
ilter(): dplyr, stats
ag():    dplyr, stats

To accurately read a rectangular dataset with readr you combine two pieces: a function that parses the overall file, and a column specification. The column specification describes how each column should be converted from a character vector to the most appropriate data type, and in most cases it's not necessary because readr will guess it for you automatically.

readr supports seven file formats with seven read_ functions:

In many cases, these functions will just work: you supply the path to a file and you get a tibble back. The following example loads a sample file bundled with readr:

rs <- read_csv(readr_example("mtcars.csv"))
arsed with column specification:
ols(
 mpg = col_double(),
 cyl = col_integer(),
 disp = col_double(),
 hp = col_integer(),
 drat = col_double(),
 wt = col_double(),
 qsec = col_double(),
 vs = col_integer(),
 am = col_integer(),
 gear = col_integer(),
 carb = col_integer()

Note that readr prints the column specification. This is useful because it allows you to check that the columns have been read in as you expect, and if they haven't, you can easily copy and paste into a new call:

rs <- read_csv(readr_example("mtcars.csv"), col_types = 
ls(
mpg = col_double(),
cyl = col_integer(),
disp = col_double(),
hp = col_integer(),
drat = col_double(),
vs = col_integer(),
wt = col_double(),
qsec = col_double(),
am = col_integer(),
gear = col_integer(),
carb = col_integer()


vignette("readr") gives more detail on how readr guess the column types, how you can override the defaults, and provides some useful tools for debugging parsing problems.

Alternatives

There are two main alternatives to readr: base R and data.table's fread(). The most important differences are discussed below.

Base R

Compared to the corresponding base functions, readr functions:

data.table and fread()

data.table has a function similar to read_csv() called fread. Compared to fread, readr functions:

Acknowledgements

Thanks to:


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.