Rmarkdown: pandoc document conversion failed with error 43 because of large number

谁说胖子不能爱 提交于 2019-11-27 08:06:37

问题


I ran into problems while knit the pdf in Rstudio via Rmarkdown. I suppose it stems from too many digits for the value of quoted r variable outside the chunk of code.

---
title: "R Notebook"
output:
pdf_document: default
html_notebook: default
---


```{r}
x <- 11111111111111
```

Testing for `r x`.

Error is

! Missing $ inserted.
<inserted text> 
            $
l.133 Testing for 1.1111111\times

pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted

Hope someone can help me out here.


回答1:


This happens because long numbers are transformed to scientific notation (like 1.1e11) when printed, and because this scientific notation makes use of latex math symbol \times. There are two workarounds:

  1. Disable scientific notation. This can be done with options(). Add this chunk at the beginning of the document:

    ```{r, echo=FALSE}
    options(scipen = 99)
    ```
    
  2. Print your number in a math environment with $ (this will preserve scientific notation):

    Testing for $`r x`$.
    


来源:https://stackoverflow.com/questions/40570234/rmarkdown-pandoc-document-conversion-failed-with-error-43-because-of-large-numb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!