On reflection, tools::R_user_dir(package = "custompkg", which = "cache")
should make this easy in R >= 4.0.0
. Each time the user invokes a model, the package could copy over the source file to the user cache while preserving the modification timestamp (file.copy(copy.date = TRUE)
) and then compile the newly copied Stan file in the cache. In theory, the model should compile at most once every package update. I am currently developing an internal package at work that uses this approach.
3 Likes