::init() renv
The renv package helps you create reproducible environments for your R projects
It section also update into R handbook
# renv for R
inital renv and create renv.lock with current loaded pacakge
show all installed pacakge
= as.data.frame(installed.packages()[,c(1,3:4)])
installed_pacakge = installed_pacakge[is.na(installed_pacakge$Priority),1:2,drop=FALSE]
installed_pacakge installed_pacakge
show all installed pacakge and uploaded pacakge
library(dplyr)
= as.data.frame(installed.packages()[,c(1,3:4)])
installed_pacakge = installed_pacakge[is.na(installed_pacakge$Priority),1:2,drop=FALSE]
installed_pacakge |> filter(Package %in% (.packages())) installed_pacakge
when using renv and install new pakcage
# it will not work
# library(lubridate)
need to install new package with renv::install
::install('lubridate') renv
library(lubridate)
check current package and renv package
::status() renv
update lock file
::snapshot() renv
check status again
::status() renv
make all current pakcage version back to renv list
::restore() renv
update all pakcage in renv. recommand do it once a year to keep package updated.
::update() renv
update renv itself only
::upgrade() renv
close renv in a project
::deactivate() renv
re enable renv in a project
::activate() renv
renv in python
set python version
::use_python() renv
check python version in renv
from sys import version as python_formatted_version
print(python_formatted_version)
list all installed pacakge in python
import os
print(os.system('pip freeze'))
install package
import os
'python3.10 -m pip install siuba') os.system(
update lock file
::snapshot() renv
uninstall package
import os
'yes | python3.10 -m pip uninstall siuba') os.system(
make all current pakcage version back to renv list
::restore() renv
install package
import os
'python3.10 -m pip install requests') os.system(
update lock file
::snapshot() renv
reference:
Robust R Code That Will Work Forever With {renv} by Albert Rapp:
https://www.youtube.com/watch?v=Oen9xhEh8PY
https://rstudio.github.io/renv/articles/renv.html