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

unnest_longer(): do not know how to convert 'value' to class “Date” #1089

Closed
selesnow opened this issue Jan 29, 2021 · 1 comment
Closed
Labels
bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames

Comments

@selesnow
Copy link

selesnow commented Jan 29, 2021

Hi, i try unnesting date column by unnest_longer(), and get do not know how to convert 'value' to class “Date”, but its works when i use unnest()`

data example

# package
library(dplyr)
library(tidyr)
library(lubridate)

# test frame
df <- data.frame(
  transaction_id = c("1", "2"),
  trade_date = as.Date(c("2019-07-01", "2019-08-01")),
  start = as.Date(c("2019-08-01", "2019-12-01")),
  end = as.Date(c("2019-10-31", "2020-02-28")),
  price = c(5, 6),
  currency = c("CAD", "CAD"),
  volume = c(10000, 5000)
)

unnest_longer example

# unnest_longer
df %>%
  group_by(transaction_id) %>% 
  mutate(start=list(seq(start, end, "months"))) %>% 
  unnest_longer(col=start)

Result:

Error in as.Date.default(value) : 
  do not know how to convert 'value' to classDate

unnest example

# unnest
df %>%
  group_by(transaction_id) %>% 
  mutate(start=list(seq(start, end, "months"))) %>% 
  unnest(col=start)

Result: OK

It`is normal behavior?

sessionInfo()

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=Russian_Ukraine.1251  LC_CTYPE=Russian_Ukraine.1251    LC_MONETARY=Russian_Ukraine.1251 LC_NUMERIC=C                    
[5] LC_TIME=Russian_Ukraine.1251    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lubridate_1.7.9          stringr_1.4.0            zoo_1.8-8                googlesheets4_0.2.0.9000 dplyr_1.0.2             
[6] tidyr_1.1.2             

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0  xfun_0.18         remotes_2.2.0     purrr_0.3.4       gargle_0.5.0.9000 lattice_0.20-41   vctrs_0.3.6      
 [8] generics_0.1.0    testthat_2.3.2    usethis_1.6.3     htmltools_0.5.0   yaml_2.2.1        utf8_1.1.4        rlang_0.4.9      
[15] pkgbuild_1.1.0    pillar_1.4.7      glue_1.4.2        withr_2.3.0       sessioninfo_1.1.1 lifecycle_0.2.0   cellranger_1.1.0 
[22] devtools_2.3.2    memoise_1.1.0     evaluate_0.14     knitr_1.30        callr_3.5.1       ps_1.4.0          curl_4.3         
[29] fansi_0.4.1       Rcpp_1.0.5        openssl_1.4.3     backports_1.1.10  desc_1.2.0        pkgload_1.1.0     jsonlite_1.7.2   
[36] fs_1.5.0          googleAuthR_1.3.0 askpass_1.1       digest_0.6.27     stringi_1.5.3     processx_3.4.4    rprojroot_1.3-2  
[43] grid_4.0.3        cli_2.2.0         tools_4.0.3       magrittr_2.0.1    tibble_3.0.4      crayon_1.3.4      pkgconfig_2.0.3  
[50] ellipsis_0.3.1    prettyunits_1.1.1 googledrive_1.0.1 assertthat_0.2.1  rmarkdown_2.4     httr_1.4.2        rstudioapi_0.11  
[57] R6_2.5.0          compiler_4.0.3   
@hadley
Copy link
Member

hadley commented Feb 17, 2021

Somewhat more minimal reprex:

library(tidyr)

df <- tibble(start = as.list(as.Date(c("2019-08-01", "2019-12-01"))))
df %>% unnest_longer(start)
#> Error in as.Date.default(value): do not know how to convert 'value' to class "Date"

Created on 2021-02-17 by the reprex package (v1.0.0)

@hadley hadley added bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames labels Feb 17, 2021
@hadley hadley closed this as completed in 99b94ee Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames
Projects
None yet
Development

No branches or pull requests

2 participants