Skip to content

read_csv reads strings with "-" as date #228

@felixhaass

Description

@felixhaass

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions