purrr icon indicating copy to clipboard operation
purrr copied to clipboard

Issue with pmap when first column of tibble is a date

Open karjamatti opened this issue 3 years ago • 1 comments

It seems that pmap doesn't work when the first column of a tibble is a date column. The issue vanishes if the columns are rearranged.

I came across this issue when trying to hash each row of a tibble using digest, but for simplicity the reprex below is simplest I could think of.

purrr::pmap(tibble::tibble(x = 1, y = 'foo', date = lubridate::ymd('2020-01-01')), ~length(c(...)))
# [[1]]
# [1] 3

purrr::pmap(tibble::tibble(date = lubridate::ymd('2020-01-01'), x = 1, y = 'foo'), ~length(c(...)))
# Error in as.Date.numeric(e) : 'origin' must be supplied

The error in the reprex was different from the original one I got, which was this:

# Error: Problem with `mutate()` input `hash_key`.
# x character string is not in a standard unambiguous format
# i Input `hash_key` is `purrr::pmap_chr(., ~digest::digest(c(...)))`.

This one also disappeared when rearranging the columns so that the first columns was something else than the date.

karjamatti avatar Jun 23 '21 10:06 karjamatti

I do not have your issue:

purrr::pmap(tibble::tibble(x = 1, y = 'foo', date = lubridate::ymd('2020-01-01')), ~length(c(...)))
#> [[1]]
#> [1] 3

purrr::pmap(tibble::tibble(date = lubridate::ymd('2020-01-01'), x = 1, y = 'foo'), ~length(c(...)))
#> Warning: All formats failed to parse. No formats found.
#> [[1]]
#> [1] 3

Created on 2022-06-28 by the reprex package (v2.0.1)

I do get a Warning. That warning comes from lubridate. The problem here is that by setting a date at the beginning, it forces a conversion to date to all other variables. When it gets to "foo", it fails.

In my version of lubridate (1.8.0) I get an NA and a warning. In yours, you get an error, but it really seems to be a parsing error from lubridate nonetheless.

character string is not in a standard unambiguous format

Maybe you have an older version?

lubridate::ymd('foo')
#> Warning: All formats failed to parse. No formats found.
#> [1] NA
packageVersion("lubridate")
#> [1] '1.8.0'

Created on 2022-06-28 by the reprex package (v2.0.1)

edo91 avatar Jun 28 '22 11:06 edo91

This looks like a base R bug let to me:

df <- tibble::tibble(date = as.Date('2020-01-01'), x = 1, y = 'foo')
c(df[[1]], df[[2]], df[[3]])
#> Error in as.Date.numeric(e): 'origin' must be supplied

Created on 2022-08-23 by the reprex package (v2.0.1)

hadley avatar Aug 23 '22 21:08 hadley