Clare Barwood
Clare Barwood

Reputation: 35

Remove_Column from a kable table which will be output as latex/pdf

I am trying to remove two columns from the below table however when knitted as a pdf from markdown I get the below error. I am unsure if this just isn't possible or if there is a work around.

ERROR: Error in remove_column(., 4:5) : Removing columns was not implemented for latex kables yet Calls: ... kable_classic -> kable_light -> kable_styling -> remove_column Execution halted

OverCortTab <- bind_rows(AlexOverCortTab$table_body,OptOverCortTab$table_body)%>% 
  mutate(Predictor=str_replace(Predictor,"TAS_Tot","Alexithymia"),
         Predictor=str_replace(Predictor,"OPT_Tot","Optimism"))%>%
  mutate(Fit=str_replace(Fit,"95%","95\\\\%"),
         Fit=str_replace(Fit,"R2","R$2$"),
         Fit=lead(Fit,n=2))%>%
        filter(Predictor !=""|Fit !="")%>%
        kable(caption = "Table 1: Hair Cortisol and Personality",
        booktabs=TRUE,
        col.names = c("Predictor","$\\beta$","$\\beta$ 95\\% CI","$\\beta$","$\\beta$ 95\\% CI","sr2","sr2 95\\% CI","r","Fit"),
        escape=FALSE) %>%
        remove_column(4:5)%>% 
        kable_classic(font_size=12)%>%
  footnote(general=c("A Significant $\\beta$-weight indicates the semi-partial correlation is also significant.","$\\beta$ represents unstandardised regression weights.","sr2 represents the semi-partial correlation squared.","Square brackets are used to enclose the lower and upper limits of the confidence interval.","* indicates p < .05", "** indicates p < .01"),escape=FALSE) %>%
  group_rows("Alexithymia",1,2,hline_before=TRUE,hline_after=TRUE,underline=TRUE)%>%
  group_rows("Optimism",3,4,hline_before=TRUE,hline_after=TRUE,underline=TRUE) ```

Upvotes: 0

Views: 834

Answers (1)

bttomio
bttomio

Reputation: 2306

Instead of removing the column inside the kbl function, you could try removing it before.

This could work, by piping select:

OverCortTab <- bind_rows(AlexOverCortTab$table_body,OptOverCortTab$table_body)%>% 
  mutate(Predictor=str_replace(Predictor,"TAS_Tot","Alexithymia"),
         Predictor=str_replace(Predictor,"OPT_Tot","Optimism"))%>%
  mutate(Fit=str_replace(Fit,"95%","95\\\\%"),
         Fit=str_replace(Fit,"R2","R$2$"),
         Fit=lead(Fit,n=2))%>%
  filter(Predictor !=""|Fit !="")%>%
  select(-c(4:5))%>%
  kable(caption = "Table 1: Hair Cortisol and Personality",
        booktabs=TRUE,
        col.names = c("Predictor","$\\beta$","$\\beta$ 95\\% CI","$\\beta$","$\\beta$ 95\\% CI","sr2","sr2 95\\% CI","r","Fit"),
        escape=FALSE) %>%
  kable_classic(font_size=12)%>%
  footnote(general=c("A Significant $\\beta$-weight indicates the semi-partial correlation is also significant.","$\\beta$ represents unstandardised regression weights.","sr2 represents the semi-partial correlation squared.","Square brackets are used to enclose the lower and upper limits of the confidence interval.","* indicates p < .05", "** indicates p < .01"),escape=FALSE) %>%
  group_rows("Alexithymia",1,2,hline_before=TRUE,hline_after=TRUE,underline=TRUE)%>%
  group_rows("Optimism",3,4,hline_before=TRUE,hline_after=TRUE,underline=TRUE) 

Upvotes: 1

Related Questions