Markdown - want to avoid reading in a large file every time before using Knit

I have a really large file that I would like to read in once and store in a data frame. Then I would like to reuse this file to create other smaller data frames files to run various models on these smaller data frames. Whenever there is output that's useful I want to detail and share with others by running another Knit.

If I close down my session and run the entire code including reading the large file and then Knit, it works. But if I then go back and adjust the code to create a new small data frame from the large data frame (without running the top chunk whose only job is to read in the large file (eval = FALSE)), then the 2nd attempt to knit bombs out. I get an error message that the smaller data frame that was created from the larger one can't be found.

Seems like this must be a very common issue but I'm not finding anything on the board how to structure the code to get this to work.


In this case I would use cache = TRUE in the chunk header

Like this

```{r, cache = TRUE}
large_data <- read_csv...

Then data will be saved and can be "reused" when you knit the Rmarkdown again

Hope this helps :slight_smile:

Brgds. Henrik

Thanks!! Seems like that should solve it.

1 Like

This topic was automatically closed 21 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.