tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
728 stars 207 forks source link

A strange behavior of parse_date_time2() when used inside the mutate function vs it is not #1038

Closed ShanikaLW closed 1 year ago

ShanikaLW commented 2 years ago

When I set lt = TRUE in parse_date_time2, it gives NA when used inside the mutate function.

df <- tibble(x = "2010-03-14 02:05:06")
df %>% 
  mutate(y = parse_date_time2(x,  "YmdHMS", tz = "America/New_York", lt = TRUE)
)
# A tibble: 1 x 2
  x                   y                  
  <chr>               <dttm>             
1 2010-03-14 02:05:06 NA 

It works fine when used as below:

parse_date_time2("2010-03-14 02:05:06",  "YmdHMS", tz = "America/New_York", lt = TRUE)
[1] "2010-03-14 02:05:06 America/New_York"

What's causing this difference?

vspinu commented 1 year ago

Sorry for long silence. This works in development version and it most likely was fixed on dplyr side. I don't see how lubridate can be the culprit here.

If the problem persists please reopen and in order to be sure that its not dplyr, parse the string outside of mutate and assign it the resulting object inside the mutate step.