A wrapper around tidyr::pack()
which stores the packed data into JSON columns.
Arguments
- .data
A data frame, a data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).
- ...
<
tidy-select
> Columns to pack, specified using name-variable pairs of the formnew_col = c(col1, col2, col3)
. The right hand side can be any valid tidy select expression.- .names_sep
If
NULL
, the default, the names will be left as is.
Examples
df <- tibble::tibble(x1 = 1:3, x2 = 4:6, x3 = 7:9, y = 1:3)
packed <- json_pack(df, x = c(x1, x2, x3), y = y)
packed
#> # A tibble: 3 × 2
#> x y
#> <chr> <chr>
#> 1 "{\"x1\":1,\"x2\":4,\"x3\":7}" "{\"y\":1}"
#> 2 "{\"x1\":2,\"x2\":5,\"x3\":8}" "{\"y\":2}"
#> 3 "{\"x1\":3,\"x2\":6,\"x3\":9}" "{\"y\":3}"