tb_summary giving error only when I specify a 'by' variable

I'm receivng the following error message despite double checking that the control_str variable is accounted for and all variables are chr or num:
Error in mutate():
:information_source: In argument: df_stats = pmap(...).
Caused by error in pmap():
:information_source: In index: 3.
Caused by error in abort():
! message must be a character vector, not a <rlang_error/error/condition> object.
Backtrace:

  1. ... %>% bold_labels()
  2. gtsummary:::safe_summarise_at(., variable = variable, fns = fns)
  3. base::tryCatch(...)
  4. base (local) tryCatchList(expr, classes, parentenv, handlers)
  5. base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
  6. value[3L]
  7. rlang::abort(message = e)
tbl1_completecases <- ComPAS_MUAC115_LinearGrowth_ForAnalysis_completecases_tbl1 %>%
  tbl_summary(
    by = control_str, 
    type = all_continuous() ~ "continuous2",
    statistic = all_continuous() ~ c("{mean} +/- {sd}",
                                     "{median} ({p25}, {p75})", 
                                     "{min}, {max}"),
    missing = "no"
  ) %>%                                          
  add_n() %>% # add column with the total number of non-missing observations
  add_p() %>% # test for a difference between groups
  modify_header(label = "**Variable**") %>% # update the column header
  add_overall() %>%
  modify_footnote(
    update = all_stat_cols() ~ "Unadjusted - complete cases"
  ) %>%
  modify_caption("**Table 1: By control group - Complete Cases**") %>%
  bold_labels()

structure(list(country = structure(c("Kenya", "Kenya", "Kenya"
), label = "Country", class = c("labelled", "character")), sex_masculine = structure(c(0,
1, 1), label = "Sex: Masculine", class = c("labelled", "numeric"
)), adm_age = structure(c(12, 11, 10), label = "Admission age in months", class = c("labelled",
"numeric")), age_oneyear = structure(c("≥ 12 months", "6 to < 12 months",
"6 to < 12 months"), label = "Age category: by one year", class = c("labelled",
"character")), age_twoyears = structure(c("6 to < 24 months",
"6 to < 24 months", "6 to < 24 months"), label = "Age category: by two years", class = c("labelled",
"character")), age_cat = structure(c("≥ 12 months to less than 24 months",
"6 to < 12 months", "6 to < 12 months"), label = "Age category: by one and two years", class = c("labelled",
"character")), adm_oedema = structure(c(0, 0, 0), label = "Edema at admission", class = c("labelled",
"numeric")), adm_muac = structure(c(108, 111, 111), label = "Admission MUAC (mm)", class = c("labelled",
"numeric")), adm_kg = structure(c(6.85, 6.9, 5.96), label = "Admission weight (kg)", class = c("labelled",
"numeric")), adm_cm = structure(c(70.7, 74.6, 65.5), label = "Admission height (cm)", class = c("labelled",
"numeric")), adm_whz06 = structure(c(-2.21, -3.88, -2.71), label = "Admission WHZ", class = c("labelled",
"numeric")), adm_haz06 = structure(c(-1.28, 0.02, -3.4), label = "Admission HAZ", class = c("labelled",
"numeric")), adm_waz06 = structure(c(-2.24, -2.82, -3.8), label = "Admission WAZ", class = c("labelled",
"numeric")), adm_fever_yn = c(0, 0, 0), adm_diarr_yn = structure(c(0,
0, 1), label = "Diarrhea reported at admission", class = c("labelled",
"numeric")), adm_cough_yn = c(0, 1, 1), cg_education_none = structure(c(0,
0, 0), label = "Maternal educational achievement - none", class = c("labelled",
"numeric")), HH_Community_Latrine = structure(c(1, 1, 1), label = "Access to latrine", class = c("labelled",
"numeric")), hh_occupation_fishingfarming = structure(c(0, 0,
0), label = "HH occupation fishing or farming", class = c("labelled",
"numeric")), HHS = c(0, 2, 0), HHS_category = structure(c("Little to no hunger in the HH",
"Moderate hunger in the HH", "Little to no hunger in the HH"), label = "HHS Category", class = c("labelled",
"character")), control_str = c("control", "control", "control"
)), row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"
))

This error usually means you need to put variable name in quotes: r by = "control_str"

tell me if it works...
if not, we will need a minimal example so we could reproduce the error.

This topic was automatically closed 21 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.