Creating a function to expedite creation of formatted flextables

Hello all,

I just recently found the amazing package flextable, and have been slowly building an APA 7 style table for my recent analysis. There's a bunch of lines I'm hoping to condense into a single function, but for some reason I always get an error when I try that says

Error: unexpected '}' in " return(table)}"

The individual lines I've been using are posted directly below:

# Produce abreviated and tidy version of describe_posterior's output for nicer table
Bayes_output=describe_posterior_fancy(Main_EffectsModel) %>% 
  select(Parameter:pd,Rhat:ESS) %>% 
  unite("89% HDI", CI_low:CI_high, sep = ", ", remove = TRUE, na.rm = FALSE) %>% 
  select(-(CI))

Model1table=flextable(Bayes_output)

Model1table<- font(Model1table,part = "all", fontname = "Times") # Font
Model1table <- fontsize(Model1table, size = 11) # Font size
Model1table <- align(Model1table, align = "center", part = "all") #center align
Model1table=add_header_lines(Model1table, values = c("Title","Table #"))
Model1table=autofit(Model1table)
Model1table<- add_footer_lines(Model1table, values = "Note. ESS= Effective Sample Size; pd= Probability of Direction; HDI= Highest Density Interval; LL= Lower Limit, UL= Upper Limit.")
Model1table=set_header_labels(Model1table,OddsRatio="Odds Ratio")

And here is my broken function. I've only made two functions before so I'm not sure quite how to trouble shoot.

apa7_Bayes_LogReg=function(table){
  table=flextable(table)
  table=font(table,part = "all" fontname = "Times")
  table=fontsize(table, size = 11)
  table=align(table, align = "center", part = "all")
  table=add_header_lines(table, values = c("Title","Table #"))
  table=autofit(table)
  table=add_footer_lines(table, values = "Note. ESS= Effective Sample Size; pd= Probability of Direction; HDI= Highest Density Interval; LL= Lower Limit, UL= Upper Limit.")
  table=set_header_labels(table,OddsRatio="Odds Ratio")
  return(table)}

Never mind, turns out a missing comma was what broke it!

I'll leave this post as a reference for anyone else who might find it helpful and attach a picture of the table it creates.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.