Closed aronatkins closed 1 year ago
This has been reported a few times before, e.g., #1319 #1328 #1768 #2021
Your case is relatively easy to deal with, since the newline is meaningless and can be safely removed, but a more general solution will require more work in kable()
(when newlines are not meaningless). For now, I tend to just let you go with the workaround, or use other packages that do support newlines. In the long run, I wish we could fix it, but I'm not sure how to properly fix it (should we simply remove all newlines when escape = TRUE
?). Thanks!
Agreed -- my case is straightforward; I just need to remove the newlines (because I know they are meaningless in this case).
ap$Imports <- gsub("\\n", " ", ap$Imports)
ap$Suggests <- gsub("\\n", " ", ap$Suggests)
ap$LinkingTo <- gsub("\\n", " ", ap$LinkingTo)
The more general case is more complicated (values that use multiple newlines to separate chunks of text, for example), but isn't easily expressed with Markdown tables constructed using pipe separators.
Are there cases where embedded newlines can produce valid tables?
To support newlines in Markdown tables, I think we must use other table formats. Pipe tables require each row to be a single line. Only multiline tables and grid tables support newlines: https://pandoc.org/MANUAL.html#tables These types of tables will require some substantial work in kable()
.
That's what thought, too. In other words: If kable is opinionated about how it produces tables, and always uses pipes, then converting newlines to whitespace (when escape=TRUE
) causes some tables to correctly render (without workarounds like mine) and will not break existing, working tables.
There are lots of other table-building options if folks want rich content within the cells.
I'm also fine if you decide to won't-fix this; I looked at open issues but neglected to search for closed issues when filing this one.
You can use kable(..., newline = ' ')
now.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.
Given the Quarto document:
It appears as if
escape=TRUE
(the default) is not rewriting the newlines and, as a result, the table formatting is broken.Workaround: Rewrite values to remove newlines.
Verified that this is an issue even as of 58e7879abda492fc4358dab2d249a30f581f0593 (current CRAN is knitr-1.42).
Using the most recent IDE daily: 2023.05.0-daily+325
By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.