How to knit a document without rerunnning code

I have a lengthy .rmd document which I have formatted ready for presentation, this includes extensive bootstrapping and takes a long time to run. I would like to knit the document for presentation as an appendix but do not want the code to run as R knits the document as this takes over 8 hours on the PCs I use.

Is there a way of knitting a document (to HTML preferably for later conversion to word) which quickly produces a document with only correctly formatted text (colours, font, spacing etc) without outputs.

Any help is always appreciated.

1 Like

If you don't want any code chunks to run you can add eval = FALSE in your setup chunk with knitr::opts_chunk$set().

```{r setup, include = FALSE}
knitr::opts_chunk$set(eval = FALSE)
```

If you want only some chunks to run you can add eval = FALSE to only the chunk headers of those you don't want to run.

I so often end up needing to remind myself of chunk options or how an option works. Luckily there is a great resource for this:

2 Likes

If your main concern is the time needed to re-run the code, another option would be to cache the chunks (or only the long-running ones). Then you could also include the output in your appendix without having to wait hours:

```{r setup, include = FALSE}
knitr::opts_chunk$set(cache = TRUE)
```
5 Likes

Thank you, that sounds perfect appreciate the help

1 Like

Thank you for the help, I'm going to try this and see which way works best.
Appreciated

2 Likes

If you haven’t used knitr‘s caching feature before, here are some references to help understand what it does (and what it doesn’t do!):

2 Likes