I used the answer to this question to create a function where I can use any number of variables in tab_cells. It works great until I try to put a multiple response set in the string I get an error Error: names not found: 'mdset(`4.2_1` %to% `4.2_13`)', 'mdset(`4.3_1` %to% `4.3_12`)'
connectionsvars <- "connected_scc, mdset(`4.2_1` %to% `4.2_13`), mdset(`4.3_1` %to% `4.3_12`)"
connectionsvar_names = trimws(unlist(strsplit(connectionsvars, split = ",")))
bannertable = function(varname, varnametitle) {
xtab = eval(substitute({
bannertable <- survey_data1 %>%
tab_cols(total(), age_range) %>%
tab_cells(eval(..[(varname)])) %>%
tab_stat_cpct(total_row_position = c("below"),
total_statistic = c("w_cpct"),
total_label = "#Total %") %>%
tab_pivot()
}))
assign(paste0(varnametitle, "Wtable"), bannertable, envir = .GlobalEnv)
}
bannertable(varname = connectionsvar_names, "connections")
How do I use multiple response sets while being able to use any number of variables in tab_cells?