Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use a very similar workflow to yours and your best bet is to abandon the often clunky <code>xtable</code> package and use the <code>pander</code> package to print your tables. You can wrap any object that you might want to display as a table in the generic <code>pander()</code> function. This is a wrapper for the <code>pandoc.table()</code> function which has several options. If you specify the option <code>style = "XXX"</code> you can achieve what you are asking about here. There are 4 different styles you can choose from; "multiline" (the default), "grid", "simple", or "rmarkdown". I frequently knit rmarkdown documents from within Rstudio and then convert them to Word documents using the pander package:</p> <pre><code>library(pander) Pandoc.convert("C:/Users/BlahBlahBlah/Document.md", format="docx") </code></pre> <p>All of the 4 table styles get turned into table objects upon conversion to .docx format, but only one table style looks right in the .docx document and the .html file that results from the initial "knit". That style is "rmarkdown". You can implement this 2 ways. One would be:</p> <pre><code>```{r table, results='asis'} pandoc.table(myTable, style = "rmarkdown") ``` </code></pre> <p>I prefer to set the table style globally at the beginning of my document however, ensuring that all my tables have the same formatting and also allowing me to use the more succinct <code>pander(x)</code> instead of the more verbose <code>pandoc.table(x, style = "someStyle")</code>:</p> <pre><code>```{r table, results='asis'} panderOptions("table.style", "rmarkdown") pander(myTable) ``` </code></pre> <p>There are some side effects of using the <code>rmarkdown</code> style however. Mainly, it does not support newline characters within cells, so buyer beware. I experimented with the different styles and eventually decided that I liked the default style of "multiline" because of it's flexibility with line breaks within cells, even though the .html files I generate look silly. This doesn't bother me though, as I really only use the .docx files that I convert from the .md files. I wrote a <a href="http://r-norberg.blogspot.com/2013/06/generating-tables-using-pander-knitr.html" rel="nofollow">blog post</a> about making nice tables that you might find useful. It weighs the pros and cons of several methods including <code>xtable()</code> and several <code>pander()</code> scenarios.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload