Search code examples
rlatexknitrpander

Rows not grouping in LaTeX rendering with pander


When I render the following table as HTML, I get expected row grouping:

library(expss)
library(dplyr)
library(pander)
library(knitr)

test_data = 
  data.table(
    division = c(rep("A",5),rep("B",5)),
    group = rep(c(rep("alpha",2),rep("beta",3)),2),
    subgroup = c("red","orange","yellow","green","blue",
                 "indigo","violet","black","white","brown"),
    ins = rnorm(10),
    outs = runif(10),
    overs = seq(1,100,10)
  )

test_data = apply_labels(test_data,
                      division = "Department",
                      group = "Center",
                      subgroup = "Team",
                      ins = "In-flow",
                      outs = "Out-flow",
                      overs = "Throughput")

test_table = 
  test_data %>% 
  tab_cells(ins, 
            outs,
            overs) %>% 
  tab_cols(division %nest% group %nest% subgroup) %>%
  tab_stat_fun(identity) %>%
  tab_pivot() %>%
  drop_rc() %>%
  tab_transpose()

test_table

enter image description here

However, when I render it as a PDF, the row grouping fails, replaced with long strings of pipe-delimited characters.

pander(test_table)

enter image description here

I think this is more of a LaTeX than R problem, but I'm not sure if it doesn't lie in the middle with pander. I would prefer to output this as a PDF, given preferences from folks "up the ladder".


Solution

  • Default output of the expss doesn't support pdf/latex. But there is an excellent package huxtable which works with pdf: So you need to use as_huxtable:

    library(huxtable)
    as_huxtable(test_table)