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

pmap converts POSIXct to numeric, but map* functions don't #495

Closed
ashiklom opened this issue Apr 12, 2018 · 2 comments
Closed

pmap converts POSIXct to numeric, but map* functions don't #495

ashiklom opened this issue Apr 12, 2018 · 2 comments

Comments

@ashiklom
Copy link

The map* and pmap functions exhibit different behavior when it comes to POSIXct inputs. map* preserves the POSIXct class, but pmap converts them to numeric, which messes up functions like strftime.

library(lubridate)
library(purrr)

l <- list(
  date = as_date("2010-01-01") + dhours(1:2)
)

f <- function(date) {
  print(class(date))
  print(date)
  strftime(date, "%H")
}

map(l$date, f)
# [1] "POSIXct" "POSIXt" 
# [1] "2010-01-01 01:00:00 UTC"
# [1] "POSIXct" "POSIXt" 
# [1] "2010-01-01 02:00:00 UTC"
# [[1]]
# [1] "20"
# 
# [[2]]
# [1] "21"
# 
try(pmap(l, f))
# [1] "numeric"
# [1] 1262307600
# [1] "Error in as.POSIXlt.numeric(x, tz = tz) : 'origin' must be supplied"
@jennybc
Copy link
Member

jennybc commented Apr 12, 2018

Duplicate of #358

@jennybc jennybc marked this as a duplicate of #358 Apr 12, 2018
@ashiklom
Copy link
Author

Oops, sorry. Thought I searched for this, but apparently not carefully enough. Closing as duplicate.

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