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

another date format - day missing preceding zeros #62

Closed
pssguy opened this issue May 3, 2017 · 2 comments
Closed

another date format - day missing preceding zeros #62

pssguy opened this issue May 3, 2017 · 2 comments

Comments

@pssguy
Copy link

pssguy commented May 3, 2017

I'd like the package to handle this, if possible

library(anytime)
library(stringr)
library(dplyr)
 df <- data.frame(date=c("Apr 3, 2016","Apr 13, 2016"),stringsAsFactors = FALSE)

As expected

df_new <-df %>% 
  mutate(newdate=anydate(date))
glimpse(df_new)

Observations: 2
Variables: 2
$ date    <chr> "Apr 3, 2016", "Apr 13, 2016"
$ newdate <date> NA, 2016-04-13

I started doing a hack (which would input a 0 if the ", "was in a particular position but at first stage had the newdate returned as a double

df_new <-df %>% 
  mutate(newdate=ifelse(str_sub(date,6,6)==",",anydate(Sys.Date()),anydate(date)))
glimpse(df_new)

Observations: 2
Variables: 2
$ date    <chr> "Apr 3, 2016", "Apr 13, 2016"
$ newdate <dbl> 17288, 16904
@eddelbuettel
Copy link
Owner

I am aware of the shortcoming, but it is one on the Boost side, and I would only accept fixes at the C++ layer.

Mucking about with this on the R side is just not release-strong enough I feel.

We do now have an alternate parser (in the GitHub version) which can do this (but is lacking the specific format with %b right now):

R> library(anytime)
R> anytime(c("4/3/2016","4/13/2016"), useR=TRUE)
[1] "2016-04-03 CDT" "2016-04-13 CDT"
R> 

The first would have failed using the default (via Boost).

@pssguy
Copy link
Author

pssguy commented May 5, 2017

Thanks for swift reply. I sorted it with an as.Date format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants