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

pivot_wider(): wrong names when names from numeric column + names_prefix #214

Closed
mgirlich opened this issue Mar 4, 2021 · 0 comments · Fixed by #215
Closed

pivot_wider(): wrong names when names from numeric column + names_prefix #214

mgirlich opened this issue Mar 4, 2021 · 0 comments · Fixed by #215

Comments

@mgirlich
Copy link
Collaborator

mgirlich commented Mar 4, 2021

Doesn't work correctly for a numeric column

library(dplyr, warn.conflicts = FALSE)
library(dtplyr)
library(tidyr)

tibble(
  id = 1,
  name = 1:2,
  value = 11:12
) %>% 
  lazy_dt() %>% 
  pivot_wider(names_prefix = "col")
#> Source: local data table [1 x 3]
#> Call:   setnames(dcast(`_DT1`, formula = id ~ name, value.var = "value"), 
#>     old = 1:2, new = c("col1", "col2"))
#> 
#>    col1  col2   `2`
#>   <dbl> <int> <int>
#> 1     1    11    12
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

Created on 2021-03-04 by the reprex package (v1.0.0)

but works when cast to character before

library(dplyr, warn.conflicts = FALSE)
library(dtplyr)
library(tidyr)

tibble(
  id = 1,
  name = as.character(1:2),
  value = 11:12
) %>% 
  lazy_dt() %>% 
  pivot_wider(names_prefix = "col")
#> Source: local data table [1 x 3]
#> Call:   setnames(dcast(`_DT1`, formula = id ~ name, value.var = "value"), 
#>     old = c("1", "2"), new = c("col1", "col2"))
#> 
#>      id  col1  col2
#>   <dbl> <int> <int>
#> 1     1    11    12
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

Created on 2021-03-04 by the reprex package (v1.0.0)

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

Successfully merging a pull request may close this issue.

1 participant