Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

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

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.1111111imes

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

Hope someone can help me out here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 imes. 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`$.
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...