5

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)
```
itpetersen
  • 1,475
  • 3
  • 13
  • 32
  • The way you have this set up the output file will be named .pdf and will be in a directory named ../Cases by Measure and Site/. Is that what you want?? – jlhoward Oct 31 '14 at 21:00
  • Yes, the output file would be named .pdf and it would be in the following directory (relative to the .Rmd file): ./Output/Cases by Measure and Site/ – itpetersen Oct 31 '14 at 21:03

1 Answers1

3

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=""))
jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • Thanks for the answer. The odd thing is that, on other PCs, I'm able to render the PDF to a new location (with spaces in the directory name) without a problem. So there might be some other issues, as well. I can't tell any systematic difference in the PCs' software versions. Any ideas how to allow spaces in the directory name? That's a pretty bizarre limitation these days. Thanks! – itpetersen Oct 31 '14 at 22:11
  • I have a weird variant of this exact problem. I get one copy from the same style of for loop and set up. Any ideas on why that might happen? I've removed my spaces etc... The one difference is a have a number of heavily formatted LaTeX lines, which themselves have inline r code. `{\bfseries \textcolor{purpleCustom}{£`r totalWeekSavings`}}` – DaveRGP Oct 02 '15 at 12:55
  • 1
    fixed, ended up being this issue, combined with https://github.com/rstudio/rmarkdown/issues/385 and http://stackoverflow.com/questions/5352099/how-to-disable-scientific-notation-in-r – DaveRGP Oct 02 '15 at 13:10