【发布时间】:2014-08-02 00:01:31
【问题描述】:
目标
我有一个长 Rmd 文件(保存在 R 项目中),我想用目录将其编织成 Html 和 PDF。
问题背景
我之前使用的是 RStudio 0.98.501。设置是:
- 文档顶部没有目录 (TOC) 命令
- 外部图像的绝对路径
-
cache=TRUE在全局块选项中
当我单击knitHtml 按钮第一次时,它创建了新文件夹:figures、cache、knitHTML 等。没有问题,一切正常。但后来我决定添加 TOC。使用Rmarkdown Version 2 page 的Output Options 部分,我在最顶部添加了 toc 命令,单击了knitHtml 按钮,但得到的输出与以前完全相同,但没有任何 TOC。所以,我决定升级到 RStudio 预览版。
问题的现状
更新到预览版后,我打开项目并单击knitHtml 按钮。它给出了未找到其中一个外部图像的错误。所以,在谢一辉的建议下,我做了以下事情:
- 复制了 R 在之前创建的所有外部图像和绘图
编织到 Rmd 文件所在的文件夹。这是项目目录中的
knitHtml文件夹。 - 所有外部图像的相对路径
-
cache=TRUE在全局块选项中
然后我点击knitHTML 按钮并得到以下错误:
output file: Trajectory1-new.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" Trajectory1-new.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output Trajectory1-new.html --smart --email-obfuscation none --self-contained --standalone --section-divs --table-of-contents --toc-depth 3 --template C:\Users\durraniu\Documents\R\win-library\3.0\rmarkdown\rmd\h\default.html --variable theme:united --include-in-header C:\Users\durraniu\AppData\Local\Temp\Rtmp0OFfmZ\rmarkdown-str10186bd23276.html --mathjax --variable mathjax-url:https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML --no-highlight --variable highlightjs=C:\Users\durraniu\Documents\R\win-library\3.0\rmarkdown\rmd\h\highlight
pandoc.exe: Could not find data file ./Trajectory1-new_files/figure-html/pdf_velocity.png
Error: pandoc document conversion failed with error 97
In addition: Warning messages:
1: In if (grepl(" ", path, fixed = TRUE)) path <- utils::shortPathName(path) :
the condition has length > 1 and only the first element will be used
2: running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" Trajectory1-new.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output Trajectory1-new.html --smart --email-obfuscation none --self-contained --standalone --section-divs --table-of-contents --toc-depth 3 --template C:\Users\durraniu\Documents\R\win-library\3.0\rmarkdown\rmd\h\default.html --variable theme:united --include-in-header C:\Users\durraniu\AppData\Local\Temp\Rtmp0OFfmZ\rmarkdown-str10186bd23276.html --mathjax --variable mathjax-url:https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML --no-highlight --variable highlightjs=C:\Users\durraniu\Documents\R\win-library\3.0\rmarkdown\rmd\h\highlight' had status 97
Execution halted
所以,我尝试了knit PDF,它成功了。输出符合预期。然后我在全局块选项中更改为cache=FALSE并单击knit HTML。花了很长时间(我的文件有很多分析)并给出了带有 TOC 作为输出的 html 文件,这是我所需要的。
我的问题是,当cache=TRUE 在 RStudio 预览版中用于 PDF 时,为什么我必须使用 cache=FALSE 来创建 html?每次只添加一个部分后,我都等不及 15-20 分钟才能看到输出。我该如何解决这个问题?
编辑
以下是头等大事:
---
title: "Sample Document"
output:
html_document:
theme: united
toc: yes
---
Trajectory: 7:50 am - 8:05 am (t1)
========================================================
```{r setup}
# set global chunk options:
library(knitr)
opts_chunk$set(cache=TRUE, fig.align='center')
```
```{r alllibraries, echo=FALSE}
library(ggplot2)
library(plyr)
library(data.table)
library(parallel)
library(xtable)
library(ggthemes)
suppressPackageStartupMessages(library(googleVis))
my.theme<-function(base_size = 12, base_family = "Trebuchet MS")
{theme(plot.title = element_text(size = rel(2)), panel.grid.major=element_line(color='grey'), panel.grid.minor=element_line(color='grey', linetype='dashed'), legend.position='bottom', legend.background = element_rect(colour = "black"), strip.text = element_text(size=13, lineheight=2))
}
```
【问题讨论】:
-
请始终在您的帖子中包含软件版本,如果有新版本可用,请更新您的软件包。此外,如果没有最小可重复的例子,就很难回答问题。
-
我使用的 RStudio 预览版是 0.98.894 版。我已经更新了所有软件包。此外,创建一个最小的可重现示例是尝试使用较小的文档自己创建相同的问题。我试过了,但在较小的文档中没有问题(文件很容易在有或没有
cache=TRUE的情况下编织)。我实际上不知道究竟是什么阻止 pandoc 将 md 文件转换为 html。错误是 97。我用谷歌搜索但找不到任何信息。请指导。 -
我再次更新了包,现在 R 找不到任何包!我正在恢复到旧版本。这似乎是目前唯一的解决方案。
-
您能否至少发布您的 Rmd 文档的 YAML frontmatter?
-
我已经发布了前事