Combining pandoc column names in r markdown

I am creating pandoc.table with a long column name that I want to wrap so that my table does not get deleted from the pdf page. I know you can use split.tables, but this eliminates the clarity of the table. Using split.cells doesn't seem to do anything, even if it is represented as a vector.

--- output : pdf_document --- ```{r,echo=FALSE, results="asis"} library(pander) mytab = data.frame(ReallySuperExtraLongColumnNameThatIWantToWrap=1:2, col2=2001:2002) pandoc.table(mytab) ``` 
+5
source share
1 answer

Next, a table will be created with a line break in the header:

 ```{r,echo=FALSE, results="asis"} library(pander) mytab = data.frame("ReallySuperExtraLongColumn\nNameThatIWantToWrap"=1:2, col2=2001:2002, check.names = FALSE) pandoc.table(mytab) ``` 

A line break is encoded with \n . This is not a permitted character in the column name, and the data.frame() function usually removes it. You can use check.names = FALSE to suppress this behavior and save the column names exactly as you entered them. Alternatively, you can override the column name on a separate line:

 mytab = data.frame(ReallySuperExtraLongColumnNameThatIWantToWrap=1:2, col2=2001:2002) names(mytab)[1] = "ReallySuperExtraLongColumn\nNameThatIWantToWrap" 

You can also set the width of the cells using split.cells . Then the line breaks will be generated automatically, however, the breaks appear only when there is a space in the column header. Example:

 ```{r,echo=FALSE, results="asis"} library(pander) mytab = data.frame("Really Super Extra Long Column Name That I Want To Wrap"=1:2, col2=2001:2002, check.names = FALSE) pandoc.table(mytab, split.cells = 15) ``` 

This gives breaks after Extra and Name. Note that you still need to check.names = FALSE , because spaces are also not allowed in frame names.

+6
source

Source: https://habr.com/ru/post/1245775/


All Articles