Skip to content

Instantly share code, notes, and snippets.

@jrauser
Created July 10, 2014 22:13
Show Gist options
  • Save jrauser/3d2e753de1fb65731a38 to your computer and use it in GitHub Desktop.
Save jrauser/3d2e753de1fb65731a38 to your computer and use it in GitHub Desktop.
This small RMarkdown files demonstrates the knitr chunk label prefix cache problem
knitr cache problem
========================================================
This markdown doc demonstrates the problem. I am using R 3.0.2 (in RStudio, if it matters) and knitr 1.5.
```{r libs}
library(knitr)
opts_chunk$set(cache=TRUE, autodep=TRUE)
library(ggplot2)
```
```{r define_function}
make_plot_data<-function(num) { return(data.frame(x=rnorm(num))) }
```
The `plot_data` chunk will not be cached. Apparently because there is another chunk named `plot`, which is a prefix match of `plot_data`.
```{r plot_data}
the_data<-make_plot_data(1000000)
```
```{r plot}
ggplot(the_data, aes(x))+geom_density()
```
```{r more_data}
other_data<-make_plot_data(1000000)
```
```{r not_a_prefix_match_of_more_data}
ggplot(other_data, aes(x))+geom_density()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment