Hopefully someonce can improve, but I found this hacky solution to work.
I'm using @ and ~ as symbols to represent where I want to text_transform function to substitute in the open and close sub tags. I tried making the text transform just return its input and having your original input with the sub tags in there to start with but it didnt work.
library(tidyverse)
library(glue)
library(gt)
library(stringr)
a<-1
b<-2
c<-3
tibble(' ' = c("Frequentist", "Bayesian"),
`Test against null` = c(glue("61%@{a}~"), glue("84%_{b}")),
`Test against MME` = c(glue("57%_{a},{c}"), glue("42%_c"))) %>%
gt() %>%
tab_source_note(
md(
"**Note:** Proportions with different subscripts have at least a 95% probability of differing by at least 10 percentage points."
)
) %>% text_transform(
locations = cells_body(),
fn = function(x) {
str_replace_all(x,
pattern = "@",
replacement = "<sub>") %>%
str_replace_all("~",
"</sub>") }
)