Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

Multiline tables with keep.line.breaks = TRUE not working for me #359

Closed Aariq closed 2 years ago

Aariq commented 2 years ago

I'm not sure if this is a pander issue or a rmarkdown issue. The following example doesn't include the manual line breaks like it's supposed to for me. The text output looks correct, but when I include this in a .Rmd document and knit it, the line breaks don't show up.

library(pander)
m <- data.frame('Value\n1', 'Value\n2')
colnames(m) <- c('Multiline\nCol1', 'Multiline\nCol2')
pandoc.table(m, keep.line.breaks = TRUE, style = "multiline")
#> 
#> -----------------------
#>  Multiline   Multiline 
#>    Col1        Col2    
#> ----------- -----------
#>    Value       Value   
#>      1           2     
#> -----------------------

Created on 2022-05-27 by the reprex package (v2.0.1)

Session info ``` r sessionInfo() #> R version 4.2.0 (2022-04-22) #> Platform: x86_64-apple-darwin17.0 (64-bit) #> Running under: macOS Big Sur/Monterey 10.16 #> #> Matrix products: default #> BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib #> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib #> #> locale: #> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] pander_0.6.5 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_1.0.8.3 digest_0.6.29 withr_2.5.0 magrittr_2.0.3 #> [5] reprex_2.0.1 evaluate_0.15 highr_0.9 stringi_1.7.6 #> [9] rlang_1.0.2 cli_3.3.0 rstudioapi_0.13 fs_1.5.2 #> [13] rmarkdown_2.14 tools_4.2.0 stringr_1.4.0 glue_1.6.2 #> [17] xfun_0.31 yaml_2.3.5 fastmap_1.1.0 compiler_4.2.0 #> [21] htmltools_0.5.2 knitr_1.39 ```

Word output:

Screen Shot 2022-05-27 at 3 26 11 PM

PDF output: Screen Shot 2022-05-27 at 3 23 22 PM

daroczig commented 2 years ago

Like in #358, I'd suggest trying using hard line breaks, e.g.

library(pander)
m <- data.frame('Value\\\n1', 'Value\\\n2')
colnames(m) <- c('Multiline\\\nCol1', 'Multiline\\\nCol2')
pandoc.table(m, keep.line.breaks = TRUE, style = "grid")

I hope this helps, and closing the issue as a related ticket is already opened at #357.