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

transpose & flatten declasses (at least dttm objects) #803

Closed
mmuurr opened this issue Nov 15, 2020 · 4 comments
Closed

transpose & flatten declasses (at least dttm objects) #803

mmuurr opened this issue Nov 15, 2020 · 4 comments

Comments

@mmuurr
Copy link

mmuurr commented Nov 15, 2020

Using purrr v0.3.4, when I transpose a data.frame with a datetime column, that column is de-classed:

> x <- tibble(now = Sys.time())

> x
# A tibble: 1 x 1
#   now
#   <dttm>
# 1 2020-11-14 23:12:35

> transpose(x)
# [[1]]
# [[1]]$now
# [1] 1605420756

Is this expected?

@mmuurr mmuurr changed the title transpose declasses (at least dttm objects) transpose & flatten declasses (at least dttm objects) Nov 15, 2020
@mmuurr
Copy link
Author

mmuurr commented Nov 15, 2020

I've just noticed that flatten does the same thing:

> list(Sys.time())
# [[1]]
# [1] "2020-11-14 23:34:39 MST"

> list(Sys.time()) %>% flatten()
# [[1]]
# [1] 1605422083

@lionel-
Copy link
Member

lionel- commented Nov 16, 2020

This will be fixed once we implement purrr on top of vctrs.

@jonathan-g
Copy link

jonathan-g commented Jan 16, 2021

In the meantime, I have found that purrr::pmap(list) is a workaround for turning a tibble into a list of rows (i.e., a list of lists where each element of the outer list is a row of the original tibble), while preserving class attributes.

library(purrr)
library(tibble)

foo <- tibble(now = Sys.time())
foo
#> # A tibble: 1 x 1
#>   now                
#>   <dttm>             
#> 1 2021-01-16 17:25:02

purrr::transpose(foo)
#> [[1]]
#> [[1]]$now
#> [1] 1610839503

purrr::pmap(foo, list)
#> [[1]]
#> [[1]]$now
#> [1] "2021-01-16 17:25:02 CST"

Created on 2021-01-16 by the reprex package (v0.3.0)

Acknowledgements

@jennybc's fabulous tutorials on data rectangling led me to this solution.

@hadley
Copy link
Member

hadley commented Aug 24, 2022

Duplicate of #471, which has moved to #875

@hadley hadley closed this as completed Aug 24, 2022
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

4 participants