简体   繁体   中英

! LaTeX Error: Environment threeparttable undefined

When using R Markdown to create a pdf a get this error:

output file: NCERA-210_Results.knit.md

! LaTeX Error: Environment threeparttable undefined.

Error: Failed to compile NCERA-210_Results.tex. See NCERA-210_Results.log for more info.
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted

My code is:

---
title: "NCERA-210 Results"
author: "NAME"
date: "8/29/2018"
output: pdf_document
---

```{r setup, echo=FALSE, results="asis", message=FALSE, warning=FALSE}

# load packages
library("MOTE")
library("tidyverse")
library("broom")
library("ggpubr")
library("markovchain")
library("gmodels")
library("scales")
library("formattable")
library("rmarkdown")
library("knitr")
library("igraph")
library("papaja")
library("citr")
```

```{r, echo=FALSE, results="hide", message=FALSE, warning=FALSE,       
fig.show="hide"} 
source("Thesis_Code.R")  
```

## Summary of Ratings
```{r 'Table Rating Count', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
apa_table(rating.dist,
caption = "Count of Ratings in Dataset")
```

## Plot of Rating Distribution
```{r 'Plot of Rating Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

ggplot(rating.dist,
   aes(Rating, Count)) + 
geom_col() +
ggtitle("Distribution of Ratings")
```

## Summary of Short Ratings
```{r 'Table Short Rating Count', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
apa_table(s_rating.dist,
caption = "Count of Short Ratings in Dataset")
```

## Plot of Short Rating Distribution
```{r 'Plot of Short Rating Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

ggplot(s_rating.dist,
   aes(Short_Rating, Count)) + 
geom_col() +
ggtitle("Distribution of Short Ratings")
```

## Summary of Co-op Location Distribution
```{r 'Co-op Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
apa_table(state.dist,
caption = "Location Distribution in Dataset")
```

## Plot of Co-op Distribution
```{r 'Plot of Co-op Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

ggplot(state.dist,
   aes(State, Count)) + 
geom_col() +
ggtitle("Distribution of Cooperatives Across the U.S.")
```

## Co-op Activity
```{r 'Co-op Activity Summary',echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(coop_activity,
      caption = "Count of Co-ops by Activity")
```

## Co-op Sales Quartiles by Decade & Short Rating
```{r 'Sales Quartiles', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(sales.qt,
caption = "Co-op Sales Quartiles by Decade & Short Rating")
```

## Co-op Liabilities by Decade & Short Rating
```{r 'Liabilities Quartiles', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(liab.qt,
caption = "Co-op Liabilities Quartiles by Decade & Short Rating")
```

## Co-op Cash Patronage Paid by Decade & Short Rating
```{r 'Cash Patronage Paid Quartiles', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(pat.paid,
      caption = "Co-op Cash Patronage Paid Quartiles by Decade & Short Rating")
```

I am using the papaja package to produce an APA style manuscript. I'm able to create word documents with the Rmd script but I get that error when the output is pdf_document. However, I am able to create a manuscript using the papaja template "APA article (6th edition) but this route requires a lot of script editing to remove the unnecessary code.

I suppose the issue has to do with threepartabble but I can't seem to find any guidance on this using R. I am using a Mac and have MacTex installed.

The fix was installing "kableExtra" For some reason the pdf does not render without it.

This proposed solution no longer appears to work.

Please see the following thread: LaTeX Error: Environment ThreePartTable undefined for the new solution, which requires an update to RMarkdown by running:

remotes::install_github('rstudio/rmarkdown')

That will correct the conflict between the threeparttablex latex package and rmarkdown. You may also have to run the following to manually install the package, as mentioned on the tinytex page , if bookdown does not automatically do so:

library(tinytex)
tlmgr_install('threeparttablex')    # install the threeparttablex package
tlmgr_update()               # update everything

Finally, I found it was necessary to terminate your R session and restart, so that book the rmarkdown package and the updated latex package were available. After that, you can use apa_table with results='as-is', for example:

```{r apatable, results='asis'}

  apa_table(head(iris, 20), caption = 'Here is a nice table!')  

```

And, bookdown will also take care of the labeling as it would do with its own knitr::kable based tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM