Using the following code, the compilation is successful but the cells in the 4th column report \makecell[1]{#\[val1,val2]}, where # is 1 to 5.
The line breaks is correctly inserted when the [ characters are substituted by ('s or various other characters.
dat <- data.frame(
parms = letters[1:5],
A = 1:5,
B = 11:15,
C = LETTERS[26:30],
D = c('1\n[va1, val2]', '2\n[va1, val2]', '3\n[va1, val2]', '4\n[va1, val2]', '5\n[va1, val2]')
)
dat %>%
mutate_all(linebreak) %>%
kable(format = 'latex', booktabs = TRUE) %>%
kable_styling() %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2))
If I also used the recommend escape = FALSE option in the kable call, I get an compilation error:
dat %>%
mutate_all(linebreak) %>%
kable(format = 'latex', booktabs = TRUE, escape = FALSE) %>%
kable_styling() %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2))
...
! Missing number, treated as zero.
<to be read again>
v
l.111 ...1 & 11 & 1 & \makecell[l]{1\\[va1, val2]}
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted