# Knitr options for case studies

**URL:** <https://discourse.mc-stan.org/t/knitr-options-for-case-studies/1073>\
**Category:** Publicity\
**Created:** [June 26, 2017, 8:24pm UTC](https://discourse.mc-stan.org/t/knitr-options-for-case-studies/1073 "2017-06-26T20:24:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronjg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/aaronjg/32/3768_2.png) [@aaronjg](https://discourse.mc-stan.org/u/aaronjg)\
**Post date:** [June 26, 2017, 8:24pm UTC](https://discourse.mc-stan.org/t/knitr-options-for-case-studies/1073/1 "2017-06-26T20:24:46Z")

</div>

Following up on:

> [@404 on Case Studies](http://discourse.mc-stan.org/t/404-on-case-studies/992/17):
>
> These html files come straight out of knitr. Please do not modify them by hand. If there are recommendations for customizing the knitr::render calls then feel free to share them in another thread. My guess is that the jquery is there to enable mathjax support.

Right now all of the case studies are fairly large because they are entirely self contained html files. If they are built as not self contained they would load faster since jquery can be loaded from a CDN, would only needed to be loaded once, and probably already cached for most users and images can be loaded in parallel in multiple queries. It currently takes about 4 seconds to load and render a single case study, which is very slow for a static page. It’s probably not too important, but if you are interested in best practices it might be worth keeping in mind.

I was looking for the original Rmd to regenerate these and make a pull request, but couldn’t find them. I was going to make a directory for each case study that has the main .html and the generated extra images, and a pdf version for offline viewing. The switch to non self-contained html can be done by adding this to the beginning of the R markdown file.

```
output:
  self_contained: false

```

This can also be done be setting  
`self_contained=FALSE` in the call to rmarkdown::html\_document

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [June 27, 2017, 9:17pm UTC](https://discourse.mc-stan.org/t/knitr-options-for-case-studies/1073/2 "2017-06-27T21:17:24Z")

</div>

We decided before to take the hit on loading and rendering time in exchange for the simplicitly of having a single file.

If someone wants to move to doing multiple files, they’d have to regenerate all the static HTML and images from the `.Rmd` and then rearrange the directories on the web server in order to put each case study in its own directory.

The original `.Rmd` files are in the linked repos.

---

<div class="post-metadata">

**Author:** ![aaronjg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/aaronjg/32/3768_2.png) [@aaronjg](https://discourse.mc-stan.org/u/aaronjg)\
**Post date:** [June 28, 2017, 11:03pm UTC](https://discourse.mc-stan.org/t/knitr-options-for-case-studies/1073/3 "2017-06-28T23:03:21Z")

</div>

Thanks for the suggestions. I just submitted a pull request for this.

[https://github.com/stan-dev/stan-dev.github.io/pull/44](https://github.com/stan-dev/stan-dev.github.io/pull/44)
