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
read_csvreturns a tibble and reports guessed types.col_typeswithcols()pins them explicitly.format_csvwrites a tibble back to text.
Keywords and builtins used here
col_charactercol_doublecolsfilterformat_csvlibraryread_csv
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.
Step 2 of 3 in Reading & selecting, step 10 of 12 in Reshaping & reading.