-
Notifications
You must be signed in to change notification settings - Fork 272
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 strips Date
#358
Comments
there were a couple of similar discussions around
hth. |
Thanks @david-jankoski - That's what I'm currently doing. Just wanted to make sure it was known, I admitted didn't look around to see if anything similar has been asked. |
I hit the same problem with pwalk |
The bug is not specific to dates; library(purrr)
x = "test"
class(x) = "foo"
pmap(list(x), identity)
#> [[1]]
#> [1] "test"
map(list(x), identity)
#> [[1]]
#> [1] "test"
#> attr(,"class")
#> [1] "foo" And as @mungojam mentioned, > pwalk(list(x), ~ print(class(.)))
# [1] "character" # should have been "foo" ... |
This is more of a known limitation rather than a bug, but we have plans to fix this. |
I found today that |
It is not intentional we've just been too busy with tidy eval and other projects :( |
No worries, I'm enjoying all your other work :) |
The root cause is this behaviour: x <- as.Date("2012-03-22")
x[[1]]
#> [1] "2012-03-22"
list(x)[[c(1,1)]]
#> [1] 15421 This seems like a base R problem? |
It seems so to me; If it fails, the default implementation of subset2 will be used for all subsets, but, IIUC, it doesn't care about the classes or attributes: https://github.com/wch/r-source/blob/58aec3ee94f2a0769974520f6cb2d99c49fb829f/src/main/subset.c#L1029-L1056 |
Related: I'd love to see a library(purrr)
library(lubridate)
library(tibble)
library(dplyr)
df <- tibble(
dttm_orig = ymd_hms(c("2018-04-01 08:00:00", "2017-03-02 03:00:00")),
tz = c("UTC", "CET"),
sales_amount = c(34, 56)
)
mutate(df, purchase_time = map2(dttm_orig, tz, ~with_tz(.x, .y)))
#> # A tibble: 2 x 4
#> dttm_orig tz sales_amount purchase_time
#> <dttm> <chr> <dbl> <list>
#> 1 2018-04-01 08:00:00 UTC 34.0 <dttm [1]>
#> 2 2017-03-02 03:00:00 CET 56.0 <dttm [1]>
mutate(df, purchase_time = map2_chr(dttm_orig, tz, ~as.character(with_tz(.x, .y))) %>% ymd_hms())
#> # A tibble: 2 x 4
#> dttm_orig tz sales_amount purchase_time
#> <dttm> <chr> <dbl> <dttm>
#> 1 2018-04-01 08:00:00 UTC 34.0 2018-04-01 08:00:00
#> 2 2017-03-02 03:00:00 CET 56.0 2017-03-02 04:00:00 Created on 2018-05-01 by the reprex package (v0.2.0). I realize this might not be top priority however I would love to vote up an issue dedicated to this specifically. |
@czeildi, if there isn't one, it sounds like you might want to open this as its own issue 👍 |
To resolve this issue, we need to make sure to file a bug in R's bugzilla. |
Just out of curiosity, why is this not just about replacing Lines 189 to 192 in d0a8081
(I'm afraid this is not a bug, since it's reasonable that the method dispatch happens only once for one method.) |
It might already be known, but calling |
@yutannihilation I was curious, too, and tested making that change in this branch. As far as I can tell that should fix this issue; or at least the test suite passes and the original simple example is resolved. |
@mikmart oh good idea. Want to do a PR? |
Thanks for the PR, @mikmart! |
As title -
purrr::pmap
seems to strip date class.Not sure if this is intended? Caught me out though :)
The text was updated successfully, but these errors were encountered: