Part of my package typesets (small) documents to all sorts of binary formats, via pandoc, latex and pdf2svg. These binary files (
*.svg) are then displayed in all kinds of places in package functions and also shown in a shiny frontend.
The details don't matter and are not interesting here. Suffice it to say, we have some binary blobs which:
- are somewhat expensive to generate (yikes, LaTeX is slow!)
- are somewhat large, but not prohibitively so (they can all stay in memory)
- are entirely derivative of the R code used to generate them (they are not the source, they should not be put under version control)
I'd like to follow these best practices / have these features:
- isolate side effects (to the file system, in this case) as much as possible,
- cache the binary blobs, so I can inexpensively access them (instead of rebuilding them)
- have this cache be invalidated, when the upstream R code changes.
My (preliminary) plan is to:
- have some
generate_bin()generate these blobs to
tempfile()and then immediately read them back into R as blobs, maybe as
generate_bin(), perhaps using
- provide some function to write these blobs to disc, should users want that (so I can isolate the side effects).
Is this completely crazy?
Of course I could also just write the blobs to disc, and track the file names in the package, but that kinda scares me:
- where would/should such blobs canonically be saved?
- how can I cache them?
- what if the user changes the working directory or some such shenanigan?
I'd appreciate any guidance or thoughts on this.