在RStudio预览版中编织Html的问题

uma*_*ani 5 r rstudio knitr

在这里,这里这里都提出了相关的问题.

目标

我有一个很长的Rmd文件(保存在R项目中),我想用目录编织成Html和PDF.

问题背景

我之前使用的是RStudio 0.98.501.设置是:

  1. 文档顶部没有目录(TOC)命令
  2. 外部图像的绝对路径
  3. cache=TRUE 在全局块选项中

当我按下knitHtml按钮,第一时间就创建新的文件夹:figures,cache,knitHTML等有没有问题,一切正常.但后来我决定添加TOC.使用Rmarkdown版本2页面上Output Options部分,我在顶部添加了toc命令,单击了按钮,但得到了与之前完全相同的输出,没有任何TOC.所以,我决定升级到RStudio Preview版本.knitHtml

当前的问题状态

更新到预览版本后,我打开了项目并单击了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
Run Code Online (Sandbox Code Playgroud)

所以,我试过knit PDF,它的工作原理.输出与预期一致.然后我改为cache=FALSE全局块选项并单击knit HTML.花了很长时间(我的文件有很多分析)并给出了带有TOC的html文件作为输出,我需要的.

我的问题是,为什么我必须在RStudio预览版中为PDF工作cache=FALSE时创建html cache=TRUE?我只能在添加一个部分后每次等待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))
}
```
Run Code Online (Sandbox Code Playgroud)

uma*_*ani 7

这可能仅作为评论,但它对我有用.

因为我最初在较旧版本的RStudio(0.98.501)中创建项目和Markdown文档,然后切换到预览版本,我认为,有必要在块选项中指定图形和缓存路径.所以,我做了以下事情:

opts_chunk$set(cache=TRUE, cache.path = 'DocumentName_cache/', fig.path='figure/')
Run Code Online (Sandbox Code Playgroud)

现在,我不必继续cache=FALSE编织HTML.在预览版中,我现在可以轻松创建目录并更改主题.