Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tables in pander, style="multiline"

I'm using RStudio 0.98.1056 on Windows 7, and whatever the current version of pander is on CRAN as of today (I just installed the package).

I'm trying to use the knitr->Markdown->.docx literate-programming workflow to create a table in Word. Some of the cells need to contain hard line breaks. I believe this should be possible based on info in the following link:

http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html

It says, "A backslash followed by a newline is also a hard line break. Note: in multiline and grid table cells, this is the only way to create a hard line break, since trailing spaces in the cells are ignored."

I'm trying to create a table with cells containing line breaks in the following way:

library(pander)
a <- c(1:10)
b <- c(11:20)
ab <- paste(a,b,sep='\n')
N <- ceiling(rpois(10,9))
labels <- paste("Question",c(1:10))
mytable <- data.frame(labels,ab,N)
pandoc.table(mytable, style="multiline")

But the newline just gets stripped. Same if I use sep="< newline>" or sep="< br>" (without leading spaces). I have also tried adding an extra backslash, in case R was "eating" the first one; and switching up the "paste" function to include each of these possible separators as a term in their own right, instead of in the sep= argument. None of these things worked.

I went to try out the example code in the pander help documentation, just as a sanity check, and it seems the issue is general -- sample code that I thought should produce multiline tables did not, on my machine.

Has anyone else gotten multiline tables in pander to work?

like image 675
ErinMcJ Avatar asked Sep 15 '14 21:09

ErinMcJ


1 Answers

Yup, please install the development version from GitHub -- this issue was fixed a few months ago. E.g.:

> panderOptions('keep.line.breaks', TRUE)
> pander(mytable)

--------------------
labels      ab   N  
----------- ---- ---
Question 1  1    11 
            11      

Question 2  2    6  
            12      

Question 3  3    13 
            13      

Question 4  4    12 
            14      

Question 5  5    6  
            15      

Question 6  6    6  
            16      

Question 7  7    11 
            17      

Question 8  8    19 
            18      

Question 9  9    10 
            19      

Question 10 10   9  
            20      
--------------------
like image 85
daroczig Avatar answered Oct 08 '22 06:10

daroczig