rstudio / vetiver-r

Version, share, deploy, and monitor models
https://rstudio.github.io/vetiver-r/
Other
179 stars 27 forks source link

Use renv to track needed packages and versions and store a hash #4

Closed juliasilge closed 1 year ago

juliasilge commented 3 years ago

In #2 I talk about loading packages but we need to figure out how to have platforms like RSC know what packages to install. RSC currently uses a manifest, not renv, so we'll need to figure out some details here.

If a user has a file that looks like this:

library(deploytidymodels)
library(pins)
library(plumber)

model_board <- board_rsconnect()

#* @plumber
function(pr) {
    pr %>%
        pr_model(model_board, "julia.silge/biv_svm", type = "class")
}

we currently will not successfully install the right packages for prediction into the app.

@topepo has already put work into creating an renv.lock file from a model to track what packages/versions are needed for prediction; I think this can either be used or repurposed.

juliasilge commented 2 years ago

Once we have an renv.lock of the subset of packages needed for prediction, we can take a hash (Barret recommends digest::digest(raw_data, algo = "spookyhash")) and store that hash in the modelops() constructor. This hash can then be looked up during modelops_pin_read() and we can decide whether to warn or error if the current environment doesn't match.

Looking up the hash during modelops_pin_read() has the benefit of covering both API startup and users who read the pin interactively to make a prediction for adhoc analyses.