readr: read_csv & read_tsv

Introduction to Importing Data in R

Filip Schouwenaars

Instructor, DataCamp

Overview

  • Before: utils package

  • Specific R packages

    • readr

    • data.table

Introduction to Importing Data in R

readr

  • Hadley Wickham

  • Fast, easy to use, consistent

  • utils: verbose, slower

install.packages("readr")
library(readr)
Introduction to Importing Data in R

CSV files

read.csv("states.csv")
         state    capital pop_mill area_sqm
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
read_csv("states.csv")
# A tibble: 5 × 4
         state    capital pop_mill area_sqm
         <chr>      <chr>    <dbl>    <int>
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
Introduction to Importing Data in R

TSV files

read.delim("states.txt")
         state    capital pop_mill area_sqm
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
read_tsv("states.txt")
# A tibble: 5 × 4
         state    capital pop_mill area_sqm
         <chr>      <chr>    <dbl>    <int>
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
Introduction to Importing Data in R

Wrapping in utils and readr

ch_2_1_slides.002.png

Introduction to Importing Data in R

Wrapping in utils and readr

ch_2_1_slides.003.png

Introduction to Importing Data in R

Let's practice!

Introduction to Importing Data in R

Preparing Video For Download...