renv wants to restart R session after activateion

Hi, I have started using renv for environment management, but I was not very successful. When I initialize a new renv environment by renv::init() it creates all the folders and files but when I activate the environment renv::activate() it outputs: "renv activated -- please restart the R session." I don't understand this and it is not well explained in the documentation. Doesn't restarting R session resets the environment? Even though it does not make sense to me, I did that but apparently the renv environment is not activated and I am in a vicious loop that does not load the environment. Any help on that is very appreciated.

> renv::activate()
- renv activated -- please restart the R session.

Hi @parharn,

You should only need to execute renv::init() and I think the renv::activate() is executed automatically. Once you run renv::init() there should be a project-level .Rprofile file create (along with the other renv/ folder and renv.lock file) that contains source("renv/activate.R") as the first line. This will activate the renv environment when you start your R session. You'll have to update your lock file with renv::snapshot() once you add the packages you need.

Once you are in an active session, if you execute .libPaths() you should see that it's now pointing to the renv/library/... folder in your project directory. Also, if you're using RStudio a quick visual check is to go to the Packages pane and see if the renv button appears next to the Update button, indicating you're using that evironment (see the attached image below).

Screenshot 2024-09-16 at 16.21.25

2 Likes

Thanks for your description @eric-hunt . Working with renv was not as I expected it when I read the docs or worked with it. There are prompts like the one that I questioned above that gives a bit of confusion to the user and also it is important that the R session is started from the renv directory. That is unlike conda for example that I had experience with and could not understand it until accidentally I started the R from renv directory.