• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

R/H03-May-2022-4,7452,657

build/H03-May-2022-

inst/H30-Nov-2021-2,8322,575

man/H30-Nov-2021-4,4093,826

src/H30-Nov-2021-8,2826,049

tests/H23-Nov-2021-3,7672,885

vignettes/H30-Nov-2021-1,141805

DESCRIPTIONH A D30-Nov-20212.5 KiB6867

LICENSEH A D23-Nov-202143 32

MD5H A D30-Nov-202112 KiB222221

NAMESPACEH A D29-Nov-20213.4 KiB155153

NEWS.mdH A D30-Nov-202140.3 KiB894607

README.mdH A D30-Nov-20216.1 KiB167123

README.md

1
2<!-- README.md is generated from README.Rmd. Please edit that file -->
3
4# readr <a href="https://readr.tidyverse.org"><img src="man/figures/logo.png" align="right" height="139" /></a>
5
6[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/readr)](https://cran.r-project.org/package=readr)
7[![R build
8status](https://github.com/tidyverse/readr/workflows/R-CMD-check/badge.svg)](https://github.com/tidyverse/readr)
9[![Coverage
10Status](https://codecov.io/gh/tidyverse/readr/coverage.svg?branch=master)](https://app.codecov.io/gh/tidyverse/readr?branch=master)
11
12## Overview
13
14The goal of readr is to provide a fast and friendly way to read
15rectangular data (like csv, tsv, and fwf). It is designed to flexibly
16parse many types of data found in the wild, while still cleanly failing
17when data unexpectedly changes. If you are new to readr, the best place
18to start is the [data import
19chapter](https://r4ds.had.co.nz/data-import.html) in R for data science.
20
21## Installation
22
23``` r
24# The easiest way to get readr is to install the whole tidyverse:
25install.packages("tidyverse")
26
27# Alternatively, install just readr:
28install.packages("readr")
29
30# Or the the development version from GitHub:
31# install.packages("devtools")
32devtools::install_github("tidyverse/readr")
33```
34
35## Cheatsheet
36
37<a href="https://github.com/rstudio/cheatsheets/blob/master/data-import.pdf"><img src="https://raw.githubusercontent.com/rstudio/cheatsheets/master/pngs/thumbnails/data-import-cheatsheet-thumbs.png" width="630" height="252"/></a>
38
39## Usage
40
41readr is part of the core tidyverse, so load it with:
42
43``` r
44library(tidyverse)
45#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
46#> ✓ ggplot2 3.3.5          ✓ purrr   0.3.4
47#> ✓ tibble  3.1.6          ✓ dplyr   1.0.7
48#> ✓ tidyr   1.1.4          ✓ stringr 1.4.0
49#> ✓ readr   2.1.0.9000     ✓ forcats 0.5.1
50#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
51#> x dplyr::filter() masks stats::filter()
52#> x dplyr::lag()    masks stats::lag()
53```
54
55To accurately read a rectangular dataset with readr you combine two
56pieces: a function that parses the overall file, and a column
57specification. The column specification describes how each column should
58be converted from a character vector to the most appropriate data type,
59and in most cases it’s not necessary because readr will guess it for you
60automatically.
61
62readr supports seven file formats with seven `read_` functions:
63
64-   `read_csv()`: comma separated (CSV) files
65-   `read_tsv()`: tab separated files
66-   `read_delim()`: general delimited files
67-   `read_fwf()`: fixed width files
68-   `read_table()`: tabular files where columns are separated by
69    white-space.
70-   `read_log()`: web log files
71
72In many cases, these functions will just work: you supply the path to a
73file and you get a tibble back. The following example loads a sample
74file bundled with readr:
75
76``` r
77mtcars <- read_csv(readr_example("mtcars.csv"))
78#> Rows: 32 Columns: 11
79#> ── Column specification ────────────────────────────────────────────────────────
80#> Delimiter: ","
81#> dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
82#>
83#> ℹ Use `spec()` to retrieve the full column specification for this data.
84#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
85```
86
87Note that readr prints the column specification. This is useful because
88it allows you to check that the columns have been read in as you expect,
89and if they haven’t, you can easily copy and paste into a new call:
90
91``` r
92mtcars <- read_csv(readr_example("mtcars.csv"), col_types =
93  list(
94    mpg = col_double(),
95    cyl = col_integer(),
96    disp = col_double(),
97    hp = col_integer(),
98    drat = col_double(),
99    vs = col_integer(),
100    wt = col_double(),
101    qsec = col_double(),
102    am = col_integer(),
103    gear = col_integer(),
104    carb = col_integer()
105  )
106)
107```
108
109`vignette("readr")` gives more detail on how readr guesses the column
110types, how you can override the defaults, and provides some useful tools
111for debugging parsing problems.
112
113## Alternatives
114
115There are two main alternatives to readr: base R and data.tables
116`fread()`. The most important differences are discussed below.
117
118### Base R
119
120Compared to the corresponding base functions, readr functions:
121
122-   Use a consistent naming scheme for the parameters (e.g. `col_names`
123    and `col_types` not `header` and `colClasses`).
124
125-   Are generally much faster (up to 10x-100x) faster depending on the
126    dataset.
127
128-   Leave strings as is by default, and automatically parse common
129    date/time formats.
130
131-   Have a helpful progress bar if loading is going to take a while.
132
133-   All functions work exactly the same way regardless of the current
134    locale. To override the US-centric defaults, use `locale()`.
135
136### data.table and `fread()`
137
138[data.table](https://github.com/Rdatatable/data.table) has a function
139similar to `read_csv()` called fread. Compared to fread, readr
140functions:
141
142-   Are sometimes slower, particularly on numeric heavy data.
143
144-   Forces you to supply all parameters, where `fread()` saves you work
145    by automatically guessing the delimiter, whether or not the file has
146    a header, and how many lines to skip.
147
148## Acknowledgements
149
150Thanks to:
151
152-   [Joe Cheng](https://github.com/jcheng5) for showing me the beauty of
153    deterministic finite automata for parsing, and for teaching me why I
154    should write a tokenizer.
155
156-   [JJ Allaire](https://github.com/jjallaire) for helping me come up
157    with a design that makes very few copies, and is easy to extend.
158
159-   [Dirk Eddelbuettel](http://dirk.eddelbuettel.com) for coming up with
160    the name!
161
162## Code of Conduct
163
164Please note that the readr project is released with a [Contributor Code
165of Conduct](https://readr.tidyverse.org/CONDUCT.html). By contributing
166to this project, you agree to abide by its terms.
167