Readr

Overview

Readr is primarily used to read in rectangular data from a delimited file into R as a tibble or write data to a file.

Rectangular data generally refers to tables.

Delimited data means that the columns/fields are delimited/separated by a character. Common delimiting characters include spaces (), commas (,), and tabs (\t).

readr homepage

Data

Rather than downloading files to then read in to R, we will use the URL of files uploaded to this website.

If you are interested in information and/or downloading the data you can view the following page: Data files

Sections

The sections of readr are summarised below.

Read

The readr::read_delim() function reads in delimited rectangular data from a file to a tibble.

Topics covered are:

  • Read_delim(): Reading in data with readr::read_delim() and specifying the delimiter with delim=. Common delimiters are comma (,), tab (\t), and space ().
  • Column types: Specifying the data types (double, integer, character, factor, logical etc.) of the columns when reading in data with readr::read_delim(). Particularly important when you want integer or factor columns.
  • Misc read options: Three miscellaneous options for readr::read_delim().
    • id=: Adds an ID column containing the file path.
    • skip=: Skips a specified number of lines from the top of the file.
    • n_max=: Specify the max number of lines/rows to read into a tibble.

Tidyverse reference page

Write

The readr::write_delim() writes tibbles and other table data to files.