Skip to content

Instantly share code, notes, and snippets.

@kbroman
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save kbroman/51dc23dee920f4b34c57 to your computer and use it in GitHub Desktop.

Select an option

Save kbroman/51dc23dee920f4b34c57 to your computer and use it in GitHub Desktop.
# these behave badly
read.csv("ragged.csv")
data.table::fread("ragged.csv")
(max_n_col <- max(sapply(strsplit( scan("ragged.csv", what=character()), ","), length)))
!> source("how_to_read_ragged.R", echo=TRUE)
> # these behave badly
> read.csv("ragged.csv")
a b
1 1 2
2 3 4
3 5 6
4 7 8
5 9 10
6 11 12
7 13 14
8 15 NA
9 16 17
10 18 19
> data.table::fread("ragged.csv")
V1 V2
1: 16 17
2: 18 19
> (max_n_col <- max(sapply(strsplit( scan("ragged.csv", what=character()), ","), length)))
Read 10 items
[1] 3
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 2 columns, instead of 3 in line 7.
a,b
1,2
3,4
5,6
7,8
9,10
11,12
13,14,15
16,17
18,19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment