I'm working with gtsummary, but I don't know why I can't save the table as Word document. The table is visualized well, although the problem is just with the saving process. This is the code I'm using for the table:
demographic_table<-df %>%
dplyr::select(Group, Diagnose,Gender,Age,Handedness,Cpz_equivalent)%>%
mutate(
Gender = case_when(Gender == "female" ~ "Female",
Gender == "male" ~ "Male",))%>%
mutate(
Group = case_when(Group == "control" ~ "Control",
Group == "patient" ~ "Patient",))%>%
mutate(
Handedness=case_when(Handedness=='right'~'Right',
Handedness=='left'~'Left',))%>%
tbl_summary(
by = Diagnose,
statistic = list(all_continuous() ~ "{mean} ({sd})",
all_categorical() ~ "{n} ({p}%)",
all_dichotomous()~"{n}"),
digits = all_continuous() ~ 2,
type = all_dichotomous()~"categorical",
label = Cpz_equivalent ~ "Clozapine dose",
missing = 'no'
)%>%
add_p()%>%
modify_spanning_header(c("stat_1", "stat_2", 'stat_3') ~ "**Diagnose**") %>%
add_overall()%>%
bold_labels()%>%
as_gt()%>%
gt::tab_options(table.font.names = "Times New Roman")
When I try to save it:
demographic_table %>%
as_flex_table() %>%
flextable::save_as_docx()
I'm getting this error: 'Error: Error in argument 'x='. Expecting object of class 'gtsummary'