Quarto slow when cache: true

I'm trying to use the execute option cache: true in Quarto but it looks to run even slower than when I turn it to false. I paste a minimal reprex below. What is wrong?

---
title: "Test"
format: pdf
execute:
  cache: true
---
Just doing something long:
```{r, cache=T}
library(tidyverse)
n <- 500000
tibble(
  x = rnorm(n),
  y = x*x + rnorm(n, sd=0.1)
) %>%
  ggplot(aes(x, y)) +
  geom_smooth() +
  geom_point()

First, opting in caching will only make the computation evaluation faster. When using R engine, this is a knitr feature for example

As advice, don't cache code having side-effect like code calling library(). When knitting a cached chunk, only the results will be load, and library won't be loaded again. This works here, but if you were using uncached code using tidyverse function it would fail. We describe this in the above link.

Then, when I run your code, the knitting only happens once. We can see the chunk is not recomputed, it skip almost instantly to pdf rendering. Thought the pdf rendering is long - probably because the PDF figure is taking time to be loaded and integrated ? Not sure...

But caching works here at least for me.

Thank you for your clarification, which helped me finding a simple solution. I managed to have a much faster built using the option dev='png' to save the cached figure as png (a much smaller file) and using pdflatex as engine instead of the Quarto's default xelatex. Here's the full code:

---
title: "Test"
pdf-engine: pdflatex
execute:
  echo: false
  cache: true
---

```{r setup}
library(tidyverse)
```

Just doing something long and stupid:

``` {r long, cache=TRUE, dev='png'}
n <- 500000
tibble(
  x = rnorm(n),
  y = x*x + rnorm(n, sd=0.1)
) %>%
  ggplot(aes(x, y)) +
  geom_smooth() +
  geom_point()
```

Glad it works !

Just to clarify, you can use pdflatex also with latex-auto-mk: true - not need to opt out. Only opt out if you don't want auto-install of packages for example.

If there is an issue with latex-auto-mk: true, I'll be interesting to know!

Also look at how to format full code content for next time

FAQ: How to Format R Markdown Source

You're right latex-auto-mk: true is not needed here since there's no bibliography or any need to recompile (I stupidly copied it from the file where I had the actual problem). Thank you also for the advice about how to properly format markdown code.
I now edited the code above to fix both issues.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.