typestar

readr in R

Fast, predictable delimited-file reading.

library(readr)
library(dplyr)

raw <- "name,score\nada,95\ngrace,88\n"
data <- read_csv(raw, show_col_types = FALSE)

typed <- read_csv(raw,
                  col_types = cols(name = col_character(),
                                   score = col_double()),
                  show_col_types = FALSE)

top <- typed %>% filter(score > 90)
out <- format_csv(top)

How it works

  1. read_csv returns a tibble and reports guessed types.
  2. col_types with cols() pins them explicitly.
  3. format_csv writes a tibble back to text.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
288
Tokens
65
Three-star pace
100 tpm

At the three-star pace of 100 tokens a minute, this run takes about 39 seconds.

Type this snippet

Step 2 of 3 in Reading & selecting, step 10 of 12 in Reshaping & reading.

← Previous Next →