Skip to content
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 reads strings with "-" as date #228

Closed
felixhaass opened this issue Aug 4, 2015 · 3 comments
Closed

read_csv reads strings with "-" as date #228

felixhaass opened this issue Aug 4, 2015 · 3 comments

Comments

@felixhaass
Copy link

read_csv() reads a string that contains a - always as a date, e.g. 3-19, but throws an error because the date is not complete. In the dataset I'm using, this denotes an ID string, however, and should be preserved as a string.

Here's a minimal working example:

fileConn<-file("test.csv")
writeLines(c("id, value","3-19, 5.0"), fileConn)
close(fileConn)

df <- read_csv("test.csv")

This produces:

> df <- read_csv("test.csv")
Warning message:
1 problems parsing 'test.csv'. See problems(...) for more details. 
> problems(df)
Source: local data frame [1 x 4]

  row col           expected actual
1   1   1 date like %Y-%m-%d   3-19

Now, this ends up as NA:

> df
Source: local data frame [1 x 2]

    id value
1 <NA>     5

@hadley
Copy link
Member

hadley commented Aug 21, 2015

More minimal reprex:

readr::read_csv("x,y
1989-90,1
1990-91,2")

Likely because CollectorDate::canParse() is accepting partial matches

@Huade
Copy link

Huade commented Aug 26, 2015

Works if specify col_types as character:

readr::read_csv("period\n2008-2012\n2009-2013", col_types = "c")

@hadley
Copy link
Member

hadley commented Sep 3, 2015

Even more minimal reprex

collectorGuess(c("1989-90", "1990-91"))

@hadley hadley closed this as completed in 391de79 Sep 3, 2015
@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants