tibble icon indicating copy to clipboard operation
tibble copied to clipboard

Referencing columns with [ ] fails when column names are created from glue

Open asadow opened this issue 3 years ago • 0 comments

Like #778, but with multiple columns. Again casting the return as a character seems to work ok.

library(tibble)

tib <- tibble(a = 1, b = 2)
tib[glue::glue("c{1:2}")] <- "bar"
#> Error: Can't assign to columns that don't exist.
#> x Columns `c1` and `c2` don't exist.
tib[as.character(glue::glue("c{1:2}"))] <- "bar"

df <- data.frame(a = 1, b = 2)
df[glue::glue("c{1:2}")] <- "bar"

Created on 2022-05-10 by the reprex package (v2.0.1)

asadow avatar May 10 '22 23:05 asadow