kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

Problems with `&` in cell text with linebreak

Open petzi53 opened this issue 6 years ago • 2 comments

Hao, thank you for kableExtra. I started to use it just 3 weeks ago and I can't live without it anymore ;-)

I encountered a problem using linebreak, whenever an ampersand is a part of the text in a table cell. For instance, using your example in Insert linebreak in table results in the following error:

! Extra alignment tab has been changed to \cr.
<template> ...egin \relax \d@llarend \endtemplate

As for a reproducible example: The code I have used:

library(knitr)
library(kableExtra)
dt_lb <- data.frame(
    Item = c("Hello\nWorld", "This & is\na cat"),
    Value = c(10, 100)
)

dt_lb %>%
    mutate_all(linebreak) %>%
    kable(booktabs = T, escape = F,
    col.names = linebreak(c("Item\n(Name)", "Value\n(Number)")))

petzi53 avatar May 30 '18 12:05 petzi53

@petzi53 Thank you very much for your kind words and for reporting this bug! I will add an escape option to linebreak and turn it on as default. 👍

haozhu233 avatar May 30 '18 14:05 haozhu233

Hi Peter, in the meantime I get around this by double-escaping the ampersand: Item = c("Hello\nWorld", "This \\& is\na cat")

rachaellappan avatar Jun 14 '18 06:06 rachaellappan