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

ymd(my_vector) silently parses "2013-0-1" as part of my_vector #236

Closed
nacnudus opened this issue Apr 28, 2014 · 3 comments
Closed

ymd(my_vector) silently parses "2013-0-1" as part of my_vector #236

nacnudus opened this issue Apr 28, 2014 · 3 comments

Comments

@nacnudus
Copy link

@nacnudus nacnudus commented Apr 28, 2014

library(lubridate)

a <- c("2013-1-1", "2013-0-1")
b <- "2013-0-1"

ymd(a)

[1] "2013-01-01 UTC" "2013-01-01 UTC"

ymd(b)

Warning: All formats failed to parse. No formats found.

[1] NA

sessionInfo()

R version 3.0.3 (2014-03-06)

Platform: i386-w64-mingw32/i386 (32-bit)

locale:

[1] LC_COLLATE=English_New Zealand.1252

[2] LC_CTYPE=English_New Zealand.1252

[3] LC_MONETARY=English_New Zealand.1252

[4] LC_NUMERIC=C

[5] LC_TIME=English_New Zealand.1252

attached base packages:

[1] stats graphics grDevices utils datasets methods base

other attached packages:

[1] lubridate_1.3.3 knitr_1.5

loaded via a namespace (and not attached):

[1] digest_0.6.4 evaluate_0.5.3 formatR_0.10 memoise_0.1

[5] plyr_1.8.1 Rcpp_0

@nacnudus
Copy link
Author

@nacnudus nacnudus commented Apr 28, 2014

Ugh, sorry about the formatting. Didn't look like that in the "preview". Can't seem to edit it now.

Loading

@nacnudus nacnudus changed the title ymd(my_vector) gives neither NA nor an error when my_vector includes "2013-0-1" ymd(my_vector) silently parses "2013-0-1" as part of my_vector Apr 28, 2014
@vspinu
Copy link
Member

@vspinu vspinu commented Apr 28, 2014

"2013-0-1" is not a date, is it? Where did you get it from?

It works by accident because the underlying C parser is a bit relaxed about the 0s in a couple of places. The format detection is rigorous, though, and this is why your b vector fails.

So your point is to make the parser fail on a right? Or make it work on b?

Loading

@nacnudus
Copy link
Author

@nacnudus nacnudus commented Apr 28, 2014

Correct, "2013-0-1" is not a date, and I would expect the parser to fail on it. I got it by doing paste(x$year, x$month, x$day, sep = "-") on dirty data that had a zero in the month column.

Thanks for all the lubridate functions that do work, by the way, they save me hours every week.

Loading

@vspinu vspinu closed this in a739131 Jun 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants