Skip to content

unnest_longer with multiple cols - values_to=glue::glue({col}_long) not working #1555

@werkstattcodes

Description

@werkstattcodes

I am trying to unnest ("make longer") two columns at the same time ("in parallel").
The values of these columns should be unnested to two new columns.

The pertaining documentation reads as:

values_to: A string giving the column name (or names) to store the unnested values in. If multiple columns are specified in col, this can also be a glue string containing "{col}" to provide a template for the column names. The default, NULL, gives the output columns the same names as the input columns.

Adapting the example from the documentation site, I get however an error.
Many thanks!

library(tidyverse)

df <- tibble(
  x = 1:2,
  y = list(1:2, 3:4),
  z = list(5:6, 7:8)
)

df %>%
  unnest_longer(c(y, z), values_to=glue::glue("{col}_long"))
  
 Error: glue cannot interpolate functions into strings.
* object 'col' is a function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions