RStudio Knitr无法将Rmd转换为PDF(Windows 7) [英] RStudio Knitr failed to convert Rmd to PDF (Windows 7)

查看:1036
本文介绍了RStudio Knitr无法将Rmd转换为PDF(Windows 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 RStudio (版本0.99.903)和knitr .Rmd 文件(请参见下文)转换为PDF文件.

I wanted to use RStudio (Version 0.99.903) and knitr to convert a .Rmd file (please see below) to a PDF file.

---
title: "test"
output: pdf_document
---

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.

当我运行编织PDF" 时,出现以下错误消息:

When I run "Knit PDF" I got the following error message:

processing file: test.Rmd
output file: test.knit.md

! Undefined control sequence.
l.87 Roses are \textcolor

pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\fuq\R\R-3.3.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43 
Execution halted

但是,如果我在该 .Rmd 文件中的任意位置添加R代码块,例如:

However, if I add a R code chunk anywhere in that .Rmd file, for example:

---
title: "test"
output: pdf_document
---

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.

```{r}
summary(cars)
```

然后我可以成功获取预期的PDF.

I could then successfully get a PDF that I expected.

但是奇怪的是,如果在上述 .Rmd 文件中设置 echo=FALSE (请参见下文)

But what was weird was that if set echo=FALSE in the above .Rmd file (see below)

---
title: "test"
output: pdf_document
---

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.

```{r, echo=FALSE}}
summary(cars)
```

然后再次,我得到了相同的错误消息:

Then again, I got the same error message:

! Undefined control sequence.
l.87 Roses are \textcolor

pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\fuq\R\R-3.3.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43 
Execution halted

我在Windows 7 64bit上工作,并获得了最新版本的MiKTex.请有人能告诉我出什么问题了吗?

I worked on Windows 7 64bit, and have got the latest version of MiKTex. Please could anyone give me some idea what was going wrong?

推荐答案

您必须包含软件包color,然后它才能工作.我不知道为什么它只在其中带有R块的情况下起作用.但是此解决方案将解决此问题:

You have to include the package color, then it works. I don't know why this works just with an R chunk in it. But this solution will solve this problem:

---
title: "test"
output: pdf_document
header-includes: \usepackage{color}
---


Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.

如果要将颜色编织为HTML,则必须使用以下代码:

If you want to knit colors to HTML, you have to use this code:

---
title: "test"
output: html_document
---

Roses are <span style="color:red">red</span>, 
violets are <span style="color:blue">blue</span>.

这篇关于RStudio Knitr无法将Rmd转换为PDF(Windows 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆