Search code examples
rr-markdownrstudiornotebook

Rmarkdown ll Issue at knitting


i was working on a report but my data is on a private network so at retrieving the data to my rmd file usually takes to long to knit. Looking out on Internet i found that you can actually add cache=TRUE at chunks specification to run the code more faster. The problem here is that when a i modified a chunk and then tried to run the code again, now the file is not knitting, running chunk by chunk i found put that a chunk is giving the following error:

"auc_month" is not found.

auc_month is a function that i defined and used it later on the report but the functions is not appearing in the chunk that is giving me the error. So i belive this error could be realted with the cache of rmd but i don't know how to solve it.

I tried to setting the cache=FALSE hopping to solve the problem but it seems is not working, i also tried to eareasing the cache folder that was create automatically at first but is also not working.


Solution

  • In a scenario like this I recommend, creating a separate R script file that:

    1. downloads the data
    2. stores it in the working directory using save() or saveRDS()
    3. in the RMD you can then load the data from the working directory and don't need to rely on chunk caching for this.

    If you don't want to create a separate file, you can also have the download & store script in a code chunk where you set the chunk option eval=FALSE. And follow that by a chunk that reads the data from disk. That way when you render the data is not downloaded, but you can manually run the chunk whenever you want to update the data.