Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating PDF from R Markdown in a different file location

I'm trying to create a PDF from an R Markdown (.Rmd) document using the rmarkdown package and pandoc in R. The problem I'm having is that I want to create a PDF in a different folder and with a different filename from the filename/folder of the .Rmd file. I'm running MiKTeX 2.9, RStudio 0.98.1087, rmarkdown 0.3.3, pandoc 1.13.1, R 3.0.2, and Windows 7-64 bit. The input file is named "Cases by Measure and Site.Rmd". I want the output file to be named <date>.pdf and placed in the following directory (relative to the .Rmd file): ./Output/Cases by Measure and Site/

I can create a PDF without a problem in the same file location:

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

Here's my attempt at creating a PDF in a different location:

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=""))

Here's the error I receive when trying to render the file to a new location:

"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 

Here are the contents of my R Markdown file:

---
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)
```
like image 929
itpetersen Avatar asked Oct 19 '22 23:10

itpetersen


1 Answers

The short answer is: the spaces in the directory name. This works:

render(input="./test.Rmd",
       output_format="pdf_document",
       output_file=paste("./Output/Cases.by.Measure.and.Site/", date, ".pdf", sep=""))
like image 120
jlhoward Avatar answered Oct 23 '22 02:10

jlhoward