gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:44:09 24 4
gpt4 key购买 nike

我正在尝试使用 rmarkdown 从 R Markdown (.Rmd) 文档创建 PDF R 中的 package 和 pandoc。我遇到的问题是我想在不同的文件夹中创建一个 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

这是我的 R 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)
```

最佳答案

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

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

关于r - 在不同的文件位置从 R Markdown 创建 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26683048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com