renv does not activate the environment
1
0
Entering edit mode
3 months ago
Parham ★ 1.6k

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.
environment renv • 454 views
ADD COMMENT
1
Entering edit mode
3 months ago
Mark ★ 1.6k

Reread the docs:

activate() enables renv for a project in both the current session and in all future sessions. You should not generally need to call activate() yourself as it's called automatically by init(), which is the best way to start using renv in a new project.

https://rstudio.github.io/renv/articles/renv.html

The steps are:

  1. Create new env renv::init()
  2. Install your packages with install.packages() or renv::install() they do essentially the same thing
  3. After installing the package and checking that your code works, you should call renv::snapshot() to record the latest package versions in your lockfile.
ADD COMMENT
0
Entering edit mode

It is not very clear by reading the docs. I have tried it multiple times but only with trial and error I realized that if I start R from the renv directory it activates the environment automatically. If I start R from anywhere else it starts base R environment. The doc can be written better specifically that many people could be coming from conda or venv to renv and can easily get confused. Thanks for the input Mark.

ADD REPLY

Login before adding your answer.

Traffic: 1950 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6