New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_csv errors if a column name is blank and cols() explicitly names an existing column name #318

Closed
cjyetman opened this Issue Nov 18, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@cjyetman

cjyetman commented Nov 18, 2015

csv <- "v1,v2,v3,v4,\n1,2,3,4,"
read_csv(csv)
read_csv(csv, col_types = "iiiii")
read_csv(csv, col_types = cols(.default = "c"))
read_csv(csv, col_types = cols(v1 = col_integer()))

all work as expected, except the last read which results in:

Error: not compatible with STRSXP

yes, CSVs with a final column with no data exist in the wild, ex. subset ESS data exported from the ESS Cumulative Data Wizard (European Social Survey)

R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] readr_0.2.2

loaded via a namespace (and not attached):
[1] rsconnect_0.4.1.4 tools_3.2.2       Rcpp_0.12.1 
@jennybc

This comment has been minimized.

Member

jennybc commented Feb 24, 2016

I'm seeing this behaviour too. In my case the empty unnamed column is in the middle, so I don't think it matters where it appears.

@cjyetman

This comment has been minimized.

cjyetman commented Feb 25, 2016

@jennybc agreed, it is not specific to unnamed columns at the end, nor does the data need to be empty... just an unnamed column is enough to cause the problem

here's a better example that doesn't imply anything other than an unnamed column...

library("readr")
csv <- "v1,,v3,v4\n1,2,3,4"
read_csv(csv)
read_csv(csv, col_types = "iiii")
read_csv(csv, col_types = cols(.default = "c"))
read_csv(csv, col_types = cols(v1 = col_integer()))

and my session info:

R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.4 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] readr_0.2.2

loaded via a namespace (and not attached):
[1] tools_3.2.3 Rcpp_0.12.3

hadley added a commit that referenced this issue Apr 29, 2016

@hadley hadley closed this Jun 2, 2016

noamross added a commit to noamross/readr that referenced this issue Jun 2, 2016

hadley added a commit that referenced this issue Jul 13, 2016

@lock lock bot locked and limited conversation to collaborators Sep 25, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.