I just came across this behaviour that seems to me a quirk. When you have a list of vectors of class `Date`

and you use `unlist()`

, the result is a vector of class `numeric`

.

I tried using `purrr::flatten()`

and `purrr::simplify(.type = "Date")`

to see if they would perform the same function as `unlist()`

while preserving the class, but they don't. `purrr::pluck()`

, however, does the job!

```
dates <- lubridate::as_date(
lubridate::ymd("2019-01-01"):lubridate::ymd("2019-01-03")
)
class(dates)
#> [1] "Date"
typeof(dates)
#> [1] "double"
dates_list <- list(dates)
unlist(dates_list) # class "Date" is converted to numeric
#> [1] 17897 17898 17899
class(unlist(dates_list))
#> [1] "numeric"
typeof(unlist(dates_list))
#> [1] "double"
purrr::flatten(dates_list) # can't create a vector of class "Date" ?
#> [[1]]
#> [1] 17897
#>
#> [[2]]
#> [1] 17898
#>
#> [[3]]
#> [1] 17899
purrr::flatten_dbl(dates_list) # can make a vector of class "numeric"
#> [1] 17897 17898 17899
class(purrr::flatten_dbl(dates_list))
#> [1] "numeric"
purrr::as_vector(dates_list) # equiv to purrr::simplify(dates_list)
#> [1] 17897 17898 17899
class(purrr::as_vector(dates_list))
#> [1] "numeric"
purrr::pluck(dates_list, 1) # can create a vector of class "Date"
#> [1] "2019-01-01" "2019-01-02" "2019-01-03"
class(purrr::pluck(dates_list, 1))
#> [1] "Date"
```

^{Created on 2020-10-02 by the reprex package (v0.3.0)}

It's all fine; I just thought it was unexpected that `unlist()`

doesn't preserve class in the way I would have expected. Any explanations to help my mental model are welcome!

It's interesting (to me) that there's no `_date`

variant of `purrr::map`

or `purrr::flatten`

.

edit: I can see that the list of possible types of a vector does not include "date". This obviously also applies to the types available to `purrr::as_vector`

I'm now learning about the difference between types, modes and classes in R

*PS I also discovered while making an initial reprex that lubridate surprisingly doesn't import reexport the %>% pipe as most other tidyverse packages do*