glue string as vector

I want to get the result of a glue_collapse as character vector. For an example

library(palmerpenguins)
tibble(species=unique(penguins$species),
       color=c("#FF6600","#047075","#C25BCC"))%>%
        glue_data('"{species}"="{color}"') |> 
        glue_collapse(sep = ",") 

My expected output is c("Adelie"="#FF6600", "Gentoo"="#047075","Chinstrap="#C25BCC")
current output: "Adelie"="#FF6600","Gentoo"="#047075","Chinstrap"="#C25BCC"

This could be a solution

a <- tibble(species=unique(penguins$species),
       color=c("#FF6600","#047075","#C25BCC"))%>%
  glue_data('"{species}"="{color}"') |> 
  glue_collapse(sep = ",")

glue("c({a})")

1 Like

Thanks. It worked well

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.