Reputation: 6155
I have asked related questions here, here and here.
I have a long Rmd file (saved in a R project) which I want to knit to Html and PDF with table of contents.
I was using RStudio 0.98.501 previously. The settings were:
cache=TRUE
in global chunk optionsWhen 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.
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:
knitHtml
folder in project directory.cache=TRUE
in global chunk optionsThen 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?
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))
}
```
Upvotes: 5
Views: 5834
Reputation: 6155
This might serve as a comment only but it worked for me.
Because I originally created the project and Markdown document in an older version of RStudio (0.98.501) and then later switched to preview release, I think, it became necessary to specify figure and cache path in chunk options. So, I did following:
opts_chunk$set(cache=TRUE, cache.path = 'DocumentName_cache/', fig.path='figure/')
Now, I don't have to keep cache=FALSE
to knit to HTML. In the preview release, I can now easily create table of contents and change theme.
Upvotes: 7