【问题标题】:Convert *.md to *.pdf using RStudio使用 RStudio 将 *.md 转换为 *.pdf
【发布时间】:2014-04-04 03:29:52
【问题描述】:

我想我有一个 MikTeX 问题。在 RStudio 中,我单击了 Knit PDF 按钮并收到此错误消息。

这是 pdfTeX,版本 3.1415926-2.3-1.40.12(MiKTeX 2.9 64 位)
pdflatex:找不到内存转储文件。
pdflatex:数据:pdflatex.fmt

然后我按照http://docs.miktex.org/manual/formats.html 的第一条指令进行操作 然后我重新启动了我的电脑。

此时我不知道是否需要添加内存转储文件,如果需要,详细说明。

然后我尝试了 Knit Word,效果很好,生成了 Word 2007 文档。

我正在使用 RStudio。我有一个 R 标记文档 Ira.Rmd。它生成文件 Ira.md 和 Ira.html。我想另存为 Ira.pdf。我在命令行上下载并运行了 pandoc

pandoc  Ira.md –o Ira.pdf. 

我收到以下错误消息。

Pandoc:从 TeX 源生成 PDF 时出错。 这是 pdfTeX,版本 3.1415926-2.3.1.40.12 pdflatex:找不到内存转储文件。 pdflatex:数据:pdflatex.fmt

有人可以简单地解释我如何执行此文件转换吗? 我正在使用以下内容。

Windows 7。 R版本:3.0.2 RStudio 版本:0.98.684

我确实阅读了https://github.com/rstudio/rmarkdown,但我仍然不明白如何转换我的文件。

更新我正在编辑我的问题。

我正在尝试将 R markdown 文件转换为 PDF。我在 R Studio 中创建了 RMD 文件。只需单击一个按钮,我就成功生成了包含 R 代码的 HTML 文件。

我使用的是 R 版本 3.0.2

我使用的是 RStudio 版本 0.98.684

我不知道以下是否相关。

我的 .Rprofile 文件包含以下行。

setwd("C:/Users/Ira/Documents/Statistics")

我跑了以下

> getwd()
[1] "C:/Users/Ira/Documents/Statistics"

我已经尝试了所有建议。谢谢你。但是,我在尝试转换为 PDF 时继续收到错误消息。我最近的帖子试图发布错误消息。

真正的Rmarkup文件是:IraAppliedStats.Rmd

单击 Knit 会生成所需的 HTML 文件。

我成功运行了命令:

install.packages("devtools"); devtools::install_github("rstudio/rmarkdown")

library(rmarkdown)

我从控制台运行了以下命令,但收到错误消息。

render(input = "toPDF2.rmd", output_format = "pdf_document", output_file = "toPDF2.pdf")

我观察了监视器。在生成了几个块后,我开始在几个块完成后看到多条消息,如下所示。

*警告 in (if (out_format(c("latex", "sweave", "listings", "markdown"))) sanitize_fn else str_c)(path, : 图路径中的点替换为 _ ("IraAppliedStats_Rmd_files/figure-latex/unnamed-chunk-10")*

每个块都有以下消息。

没有R代码的普通文本

文档的大部分内容是 R 代码。当我生成 HTML 文件时,会出现同一行。

错误信息的本质似乎是。

pandoc.exe:从 TeX 源生成 PDF 时出错。 这是 pdfTeX,版本 3.1415926-2.3-1.40.12(MiKTeX 2.9 64 位) pdflatex: 找不到内存转储文件。

然后我使用记事本将以下两行添加到 IraAppliedStats.md 文件的顶部。

*标题:IraAppliedStats.md 输出:pdf_document*

我关闭了记事本。

我再次运行命令。

render(input = "IraAppliedStats.Rmd", output_format = "pdf_document", output_file =    "IraAppliedStats.Rmd.pdf")

这似乎没有帮助,因为我再次收到一条错误消息并且没有生成 PDF 文件。

添加/编辑结束

【问题讨论】:

  • 看看pander - 可能会让生活更轻松。
  • 我看了看。有没有我可以用来进行转换的命令?
  • 编织.Rmd,然后使用Pandoc.convert。但是您的问题可能仍然存在。也许thisthisthis 可能会有所帮助。
  • @user2738483 我认为我们需要查看您的降价文件的全部内容来诊断问题是否出在文件或您的 R/RStudio 设置上。请创建一个 gist 包含您的降价文件的完整代码,然后将 URL 粘贴到您的问题中。

标签: r pdf markdown rstudio


【解决方案1】:

使用rmarkdown package(包含在 RStudio 版本 0.98.682、the current preview release)将 Rmd 转换为 PDF 非常简单,只有一个函数可以进行转换:render

这是我的 markdown 文件(在 RStudio 中启动新 Rmd 时创建的示例文件),假设它被称为 Untitled.Rmd 并保存在工作目录中(假设您的 LaTeX 发行版完全是最新的,并且您拥有最新版本的 Pandoc):

---
title: "Untitled"    # you must have lines similar to these in your Rmd file
output: pdf_document # this is how R knows to convert this file to a PDF
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. Click the **Help** toolbar button for more details on using R Markdown.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

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

You can also embed plots, for example:

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

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

然后我在控制台中运行:

library(rmarkdown)
render("Untitled.Rmd") # you could also use "Untitled.md"

然后我在我的工作目录中得到Untitled.pdf,如下所示:

或者,如果您不能使用该版本的 RStudio,或者不想在您的降价代码中包含 title:output: 行,那么这是执行此操作的常用方法:

  # Load packages.  
  require(knitr)
  require(markdown)

  # Process your .Rmd and generate a .pdf file 
  # (including smart punctuation and grey background of code blocks)
  # For this step you'll need to have two other programs installed on your computer
  # 1. Pandoc: http://johnmacfarlane.net/pandoc/installing.html
  # 2. LaTeX: follow the instructions on the Pandoc download page

  filen <- my_rmd_filename # name of the markdown file without .Rmd suffix
  knit(paste0(filen,".Rmd"))
  system(paste0("pandoc -s ", paste0(filen,".md"), " -t latex -o ", paste0(filen,".pdf"), " --highlight-style=tango  -S"))

  # Now find the location on your computer where the PDF file was created:
  getwd()

有关我为此使用的软件包和版本的更多详细信息:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rmarkdown_0.1.4

loaded via a namespace (and not attached):
[1] evaluate_0.5.1 formatR_0.10   knitr_1.5      stringr_0.6.2  tools_3.0.2    yaml_2.1.10

【讨论】:

  • 如何下载 rmarkdown 库? > library(rmarkdown) library(rmarkdown) 中的错误:没有名为“rmarkdown”的包
  • 通过这些代码行:install.packages("devtools"); devtools::install_github("rstudio/rmarkdown") 我认为它也包含在我所指的 RStudio 版本中。
  • @user2738483 你的markdown文件中必须有以title: Ira.mdoutput: output: pdf_document开头的行。
  • 谢谢。但是,我仍然无法生成 PDF 文件。在我详细介绍我最近的尝试之前,我想了解可能相关或不相关的信息。当我第一次开始使用 R 标记时,我的文件位于某个子目录中。我记得,由于找不到某些文件,代码失败了。然后我将我的文件移动到我的主 R 目录,然后我生成了非常好的 HTML 文件。我的 .Rprofile 文件包含以下行。 setwd("C:/Users/Ira/Documents/Statistics") 我创建了一个名为 toPDF2.rmd 的新文件
  • 跟随你的cmets是不可能的。请编辑您的原始问题以包含足够的详细信息,以便我们重现您的情况。
【解决方案2】:

你必须在安装 MikTek 后安装 RStudio。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 2021-08-21
    • 2017-01-24
    • 2017-05-27
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多