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)
Doesn't work correctly for a numeric column
Created on 2021-03-04 by the reprex package (v1.0.0)
but works when cast to character before
Created on 2021-03-04 by the reprex package (v1.0.0)