从R Markdown在不同的文件位置创建PDF

时间:2014-10-31 20:38:27

标签: r latex pandoc r-markdown pdflatex

我正在尝试使用rmarkdown包和R中的pandoc从R Markdown(.Rmd)文档创建PDF。我遇到的问题是我想要创建一个不同的PDF文件夹和.Rmd文件的文件名/文件夹中的文件名不同。我正在运行MiKTeX 2.9,RStudio 0.98.1087,rmarkdown 0.3.3,pandoc 1.13.1,R 3.0.2和Windows 7-64位。输入文件名为“Cases by Measure and Site.Rmd”。我希望输出文件名为<date>.pdf并放在以下目录中(相对于.Rmd文件):./Output/Cases by Measure and Site/

我可以在同一个文件位置创建一个没有问题的PDF:

library("rmarkdown")
render(input="./R Scripts/Reports/Cases by Measure and Site.Rmd",
       output_format="pdf_document")

以下是我尝试在其他位置创建PDF:

library("rmarkdown")
date <- Sys.Date()
render(input="./R Scripts/Reports/Cases by Measure and Site.Rmd",
       output_format="pdf_document",
       output_file=paste("./R Scripts/Reports/Output/Cases by Measure and Site/", date, ".pdf", sep=""))

这是我在尝试将文件渲染到新位置时收到的错误:

"C:/Program Files/RStudio/bin/pandoc/pandoc" Cases_by_Measure_and_Site.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output "./R Scripts/Reports/Output/Cases by Measure and Site/2014-10-31.pdf" --template "C:\PROGRA~1\R\R-30~1.2\library\RMARKD~1\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in" 
pandoc.exe: Could not find image `R%20Scripts\Reports\Output\Cases%20by%20Measure%20and%20Site\2014-10-31_files/figure-latex/unnamed-chunk-2-1.pdf', skipping...
! Missing $ inserted.
<inserted text> 
            $
l.136 ...files/figure-latex/unnamed-chunk-2-1.pdf}

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" Cases_by_Measure_and_Site.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output "./R Scripts/Reports/Output/Cases by Measure and Site/2014-10-31.pdf" --template "C:\PROGRA~1\R\R-30~1.2\library\RMARKD~1\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43 

以下是我的Markdown文件的内容:

---
title: "My Title"
author: "My Name"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output: pdf_document
---

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

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

1 个答案:

答案 0 :(得分:2)

简短的回答是:目录名称中的空格。这有效:

render(input="./test.Rmd",
       output_format="pdf_document",
       output_file=paste("./Output/Cases.by.Measure.and.Site/", date, ".pdf", sep=""))