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.
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.
1 answer
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:
- Create new env
renv::init() - Install your packages with
install.packages()orrenv::install()they do essentially the same thing - After installing the package and checking that your code works, you should call
renv::snapshot()to record the latest package versions in your lockfile.
Log in to answer this question.