0

In an effort to apply the MLOps "shift left" approach I switched from virtual environments to containers for each project. The thing is, that I want to take a record of the R packages' version that I use, so that when I build my container from a Dockerfile I have a container with al the right packages.

My current approach is to use the renv lockfile and call renv::restore() in the Dockerfile. This approach works but whenever I do a snapshot of the environment renv creates all other hooks such as the renv folder and the .Rprofile which are useless in my container since the only environment I have is the one of the container.

Is there a clever way to do it?

Marco Repetto
  • 336
  • 2
  • 15
  • Would `devtools::install_version` work for you? – Julian_Hn Aug 18 '21 at 11:13
  • The problem is that I want also a record as `renv` does with the lock file, with `devtools::install_version` I need to take that record by myself and update it manually every time. Correct me if I'm wrong – Marco Repetto Aug 18 '21 at 11:16
  • That is correct. But you could write a helper function to query your attached namespace and print the results of loaded packages + version to a file in the same way `renv::snapshot` does. Then in the Dockerfile you can just run the 'restore' script. – Julian_Hn Aug 18 '21 at 11:34
  • If all you're doing is calling `renv::snapshot()`, then this extra infrastructure you're talking about shouldn't be getting written out. Can you share the entirety of the code you're using? – Kevin Ushey Aug 19 '21 at 19:10
  • Thanks Kevin for reaching out, you mean both the `Dockerfile` and the R script? – Marco Repetto Aug 20 '21 at 06:58

0 Answers0