使用RStudio将*.md转换为*.pdf

use*_*483 3 pdf markdown r rstudio

我想我有一个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. 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息.

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")
Run Code Online (Sandbox Code Playgroud)

我跑了以下

> getwd()
[1] "C:/Users/Ira/Documents/Statistics"
Run Code Online (Sandbox Code Playgroud)

我尝试了所有的建议.谢谢.但是,在尝试转换为PDF时,我仍然收到错误消息.我最近的帖子试图发布错误消息.

真正的Rmarkup文件是:IraAppliedStats.Rmd

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

我成功运行了命令:

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

library(rmarkdown)
Run Code Online (Sandbox Code Playgroud)

从控制台我运行以下命令,但我收到一个错误.

render(input = "toPDF2.rmd", output_format = "pdf_document", output_file = "toPDF2.pdf")
Run Code Online (Sandbox Code Playgroud)

我观察了显示器.在生成几个块之后,我开始在几个块完成后看到诸如以下的多个消息.

*警告(if(out_format(c("latex","sweave","listing","markdown")))sanitize_fn else str_c)(path,:数字路径中的点用_替换("IraAppliedStats_Rmd_files/figure-latex /无名-块-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")
Run Code Online (Sandbox Code Playgroud)

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

添加/编辑结束

Ben*_*Ben 5

使用rmarkdown软件包(包含在RStudio版本0.98.682,当前预览版本中)将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.
Run Code Online (Sandbox Code Playgroud)

然后我在控制台中运行:

library(rmarkdown)
render("Untitled.Rmd") # you could also use "Untitled.md"
Run Code Online (Sandbox Code Playgroud)

然后我进入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()
Run Code Online (Sandbox Code Playgroud)

有关我正在使用的包和版本的更多详细信息:

> 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
Run Code Online (Sandbox Code Playgroud)

  • 你的评论是不可能的.请编辑原始问题以包含足够的详细信息,以便我们重现您的情况. (2认同)