简体   繁体   中英

Why "Knit to pdf" in RMarkdown throws error?

I have installed tinytex package in R. While using R Markdown, I can not knit to pdf, even though I can knit to html.

I have tried knit to html, that works. But knit to pdf shows error.

I get the following error message:

Error: Failed to compile New_Rmamrkdown.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See New_Rmamrkdown.log for more info.
In addition: Warning message: package 'tidyverse' was built under R version 3.5.3
Execution halted

It requires an additional third party software(latex), there are various softwares to do the task. Try this miktex . I tried in my Ubuntu OS with RStudio, it works good. Install this package, and please mention whether it works for you!

Step 1: To fix this issue, go to Tools ---> Global Options ---> Sweave in R Studio.

  • Then under Typeset LaTex into PDF using select XeLaTex .
  • Under LaTex Editing and Compilation , tick "Use tinytex when compiling.tex files.
  • Click Apply and Ok .

Step 2: In R Markdown, install tinytex in an R chunk

```{r}
tinytex::install_tinytex(force = TRUE)
library(tinytex)

Step 3: In the header block, type the output as:

output:
  pdf_document:
    latex_engine: xelatex

Select the Knit to PDF and your document should knit correctly.

If any of these help, kindly upvote it so more people can see the solution that worked. Cheers!!!

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