I have asked related questions here, here and here.
Goal
I have a long Rmd file (saved in a R project) which I want to knit to Html and PDF with table of contents.
Problem Background
I was using RStudio 0.98.501 previously. The settings were:
- No table of contents (TOCs) command at the top of document
- Absolute paths to external images
cache=TRUE
in global chunk options
When I clicked the knitHtml
button first time it created new folders: figures
, cache
, knitHTML
, etc. There was no problem, everything worked fine. But then I decided to add TOCs. Using the Output Options
section at Rmarkdown Version 2 page, I added the toc command at the very top, clicked the knitHtml
button but got the very same output as before without any TOCs. So, I decided to upgrade to RStudio Preview release.
Current State of Problem
After updating to preview release, I opened the project and clicked knitHtml
button. It gave the error that one of the external images was not found. So, upon Yihui Xie's advice I did following:
- Copied all the external images AND plots created by R during previous
knittings to the folder where the Rmd file was. This was the
knitHtml
folder in project directory. - Relative paths to all external images
cache=TRUE
in global chunk options
Then I clicked the knitHTML
button and got following error:
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
So, I tried knit PDF
and it worked. The output was as expected. Then I changed to cache=FALSE
in global chunk options and clicked knit HTML
. It took long (my file has lots of analyses) and gave the html file with TOCs as output, what I required.
My question is, why do I have to put cache=FALSE
for creating html when cache=TRUE
works for PDF in RStudio preview release? I can't wait for 15-20 minutes every time to see output after just adding a single section. How can I resolve this?
EDIT
Following is the front matter:
---
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))
}
```