OlivierBinette / cache

Easily cache and retrieve computation results in R
Other
6 stars 1 forks source link

Caching files #6

Open ivakru opened 2 years ago

ivakru commented 2 years ago

Hello.

Thank you for this nice package.

I would like to implement a feature that evaluated code to create a file. Use cases are downloading files and saving plots.

I would like to implement an interface like this:

cache_file("data/table.csv" = download.file("www.example.com/data.csv", "data/table.csv"))

cache_file("results/figure_1.png" = ggsave("results/figure_1.png"))

The function should check if the file exists, and if it does not, evaluate the code. Afterwards, it checks if the requested file has been created, and issues a warning if it has not been.

To make sure that the file is updated on code change, we can do the following: A symlink to the output file could be created, e.g. .cache-R/data:table.csv_@_HASH.link - for the first example above. This way, if we change the download URL, the download.file expr should be evaluated again.

Is something like this within the scope of a package? Would you accept a pull request?

OlivierBinette commented 2 years ago

Hi @ivakru, I think this would be a very useful addition the the package. I often need to cache files in this way and it will be handy to have this part of the package. I'll review your pull requests.