Note that in both these cases, it is directed towards using pandoc to convert from markdown to your desired document type, however using style='rmarkdown' will create tables that are compatible with this markdown package and inbuilt conversion in rstudio.
Just wanted to update this with what I settled on doing. I am using the hwriter package right now to print out tables, and using the row.* and col.* features to put CSS classes on to different elements. Then, I wrote custom CSS to make my display as I wanted it. So, here's an example in case anyone else is dealing with something similar.
First, create a file that will do the knitting and change the Markdown into HTML:
FILE: file.Rmd
Report of Fruit vs. Animal Choices
==================================
This is a report of fruit vs. animal choices.
```{r echo=FALSE,results='asis'}
library(hwriter)
set.seed(9850104)
my.df <- data.frame(Var1=sample(x=c("Apple","Orange","Banana"),size=40,replace=TRUE),
Var2=sample(x=c("Dog","Cat","Bunny"),size=40,replace=TRUE))
tbl1 <- table(my.df$Var1,my.df$Var2)
tbl1 <- cbind(tbl1,rowSums(tbl1))
tbl1 <- rbind(tbl1,colSums(tbl1))
colnames(tbl1)[4] <- "TOTAL"
rownames(tbl1)[4] <- "TOTAL"
# Because I used results='asis' for this chunk, I can just use cat() and hwrite() to
# write out the table in HTML. Using hwrite()'s row.* function, I can assign classes
# to the various table elements.
cat(hwrite(tbl1,
border=NA,
table.class="t1",
row.class=list(c("header col_first","header col","header col","header col", "header col_last"),
c("col_first","col","col","col","col_last"),
c("col_first","col","col","col","col_last"),
c("col_first","col","col","col","col_last"),
c("footer col_first","footer col","footer col","footer col","footer col_last"))))
```
The code above would give you the following figure (in the example this is the pdf output, but since the table is in markdwon, you could knit into html or word too).
From here - and reading other people´s code - you can figure out how to manipulate the text to generate the table you want and create more personalized functions.
To write / create Markdown tables in R, you can also use MarkdownReports'MarkDown_Table_writer_DF_RowColNames() or MarkDown_Table_writer_NamedVector() functions. You just pass on a data frame / matrix with dimension names, or a vector with names, and it parses & writes out the table in Markdown format.