5

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:

  1. No table of contents (TOCs) command at the top of document
  2. Absolute paths to external images
  3. 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))
}
```
Community
  • 1
  • 1
umair durrani
  • 5,597
  • 8
  • 45
  • 85
  • Please always include the software versions in your post, and update your software packages if new releases are available. Besides, it is hard to answer a question without a minimal reproducible example. – Yihui Xie Jun 12 '14 at 06:17
  • The preview release of RStudio I am using is version 0.98.894. I have updated all packages. Also, to create a minimal reproducible example is to try to create the same problem myself with a smaller document. I tried that but there was no problem (file was easily knitted with or without `cache=TRUE`) in smaller documents. I don't actually know what exactly is stopping pandoc to convert the md file to html. The error is 97. I googled it but couldn't find any info. Please guide. – umair durrani Jun 12 '14 at 13:32
  • I updated the packages again and now R can't find any package! I am reverting back to older version. This seems to be the only solution for now. – umair durrani Jun 12 '14 at 15:02
  • Can you post at least the YAML frontmatter of your Rmd document? – Yihui Xie Jun 12 '14 at 22:04
  • I have posted front matter – umair durrani Jun 13 '14 at 20:18

1 Answers1

7

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.

umair durrani
  • 5,597
  • 8
  • 45
  • 85