Reputation: 1027
I have been trying to display tables in a document. When I use kable
the output in the docx
is not displayed as a table. I can use pander
to generate the table properly but this is not optimal because I will not be able to generate captions.
---
title: "My Title"
output:
bookdown::word_document2:
fig_caption: yes
reference_docx: G:/My Drive/Projects/R15_Pipeline/R15Dir/styles/Brain_template.docx
bookdown::pdf_document2:
toc: no
link-citations: no
site: bookdown::bookdown_site
bibliography: G:/My Drive/ZoteroRPlugin/Report_references.bib
csl: G:/My Drive/ZoteroRPlugin/styles-master/dependent/brain.csl
---
```{r setup, include=FALSE, cache=FALSE, echo=FALSE}
#create a table
smoke <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE)
colnames(smoke) <- c("High","Low","Middle")
rownames(smoke) <- c("current","former","never")
smoke <- as.data.frame(smoke)
```
Here is an example using pander where the table is displayed properly but no caption. For example Table \@ref(tab:table1)
```{r table1, echo = FALSE}
pander(smoke, booktabs=T, caption = "Descriptives per Group")
```
Here is an example using kable. Table \@ref(tab:table2) which does not work
```{r table2, echo = FALSE}
knitr::kable(smoke, format="markdown", caption = "Descriptives per Group")
```
Upvotes: 3
Views: 3302
Reputation: 1027
Thanks for your help. I was able to locate the source of the error. Although I am not sure why it occurs. In my code I load data using the following code
pacman::p_load(apastats,kableExtra, grid, captioner, citr)
#devtools::install_github("haozhu233/kableExtra", force = T)
load("data/data.RData") #load the data from createTablePlots.R
load("data/data2.RData") #load the data from newStatsSigTables.R
load("data/tables.RData") #load the data from createTablePlots.R
load("data/TrialErrorsTables.RData") #load the data from newStatsSigTable.R
load("data/statsProj2.RData")
This code would cause the error as shown in the screenshot. After some trial and error this error seems to be a conflict with the kableExtra
package. When I remove this package from the lines I am able to get the correct output. I have reported this as a bug on KableExtra's GitHub
Upvotes: 1