如果我有用户的消息列表,我正在尝试保留一个数据框。我希望能够用我引用的列中的内容替换我的消息中的变量。
例如,这有效:
df <- data.frame(id = rep(1:3, each = 3),
this = rep(letters[1:3], each = 3),
that = rep(letters[24:26], each = 3),
foo = rep(c("apple", "pear", "banana"), each = 3))
df %>% mutate(message = glue("{this} is {that}"))
但这不会:
library(tidyverse)
library(glue)
verbiage <- data.frame(id = 1:3,
message = c("{this} is {that}", "{foo} is something", "something is {foo}"))
verbiage
df <- data.frame(id = rep(1:3, each = 3),
this = rep(letters[1:3], each = 3),
that = rep(letters[24:26], each = 3),
foo = rep(c("apple", "pear", "banana"), each = 3))
df
df %>%
inner_join(verbiage, by = "id") %>%
mutate(message = glue(message))