To initialise a renv project, simply enter:
if(!"renv" %in% installed.packages()[, "Package"]) install.packages("renv") # install renv if it doesn't exist on your system
renv::init(bare = TRUE)
into the R console and your project will be created using renv. From here, install your required package list using the instructions below.
An introduction to renv can be found here.
Installing pacakages can be done using either install.packages("package_name")
or renv::install("package_name")
. To install a specific package version, you simply need to use renv::install("[email protected]")
. Feel free to try it on renv::install('[email protected]')
.
To install remotely, you simply need to enter the github suffix/project location. As an example, here's a package we're installing remotely in order to get the live version which isn't available on CRAN renv::install('RinteRface/bs4Dash)'
. Again, feel free to run this if you'd like to test it out.
To update the package list, simply enter renv::snapshot()
. This will open a prompt which will ask if you want to proceed (simply type y). Updates are added to renv.lock
. If you wish to remove packages, simply delete them from here.
Note: You're best only adding packages you need for your project. This reduces the total number of packages that will be installed for future users and will ensure copying the package list is quicker and more efficient.
This step is only needed if you're going to be working on a project with a renv.lock
file that's been previously created and updated by another user.
To install the package list found within renv.lock
simply run the following in a console window renv::restore()
. If new packages are added by another user, renv::restore()
will simply install your missing packages.
Note: if you need to reclone the project at any point, you'll need to reinstall all packages. Renv works the same as virtual envs in python and simply installs the required packages in your given project.
For further info, please see both:
# other packages can be installed using
renv::install("dplyr")
# specific versions require an @ call
renv::install("[email protected]")
# packages only available on github can be installed through
renv::install("moj-analytical-services/mojSuppression")
# and critically, you also need to update the packages you install
renv::snapshot() # takes whatever you've installed and puts them in renv.lock
# to copy someone else's updates
renv::restore() # copy the installed list of packages