renv non typical use case

I currently don't use the .Rproj files and do not need to share my code with anyone or deploy any R project in my R environment. So i'm interested in quite restricted applications of renv R package.

I.e. the main reason why i'd like to use renv is that different R packages require different versions of the same dependencies. And when i install a new R package it may damage previously installed R packages.

By applying the renv i'd like to achieve two goals:

-be able to create a clean R-base environment at any time and install a new package in that environment so that the new installation will not interfere with any previously installed packages
-be able to easily turn on/off any virtual environment and switch between different virtual environments

Could you help me, please, with where i can find examples of workflow for my restricted use case of renv?

I think renv will be able to help with parts of these; let me enumerate my thoughts below.

When an renv project is activated, the project will get an isolated project library, and renv will also ensure that only base R packages are visible to the R session. (That is, if other addon packages are installed into the default library paths, those won't be accessible by default.)

This doesn't necessarily help if you need to install brand new plain R installations, though -- for that case, I'd point at GitHub - r-lib/rig: The R Installation Manager · GitHub.

be able to easily turn on/off any virtual environment and switch between different virtual environments

In general, you can't really switch between different renv environments in a single R session, but you can load different renv projects / libraries in new R sessions. What you describe sounds somewhat similar to renv profiles; e.g. Project profiles • renv.

In any event, if you haven't already, I strongly recommend browsing the documentation available at Project Environments • renv.

1 Like

Thank you so much for your reply!

I definitely have to dig into renv documentation. Thank you for the links you provided!

Let me please ask you one more question. If i reinstall R and RStudio, then i will install the renv package. But i will restrict renv usage to only two of its functions for beginning:

  1. renv::install() instead of regular install.packages() for any new R package installation

  2. renv::use() to load desirable R package or its version from the renv libraries cache

Can using just renv::install() and renv::use() functions allow me to achieve my first goal without using RStudio Projects?

"-be able to create a clean R-base environment at any time and install a new package in that environment so that the new installation will not interfere with any previously installed packages"

Or may the above-mentioned approach lead to corruption of installed R libraries or their incorrect performance?