knitr::opts_chunk$set( eval = FALSE )
Follow each step carefully until section "You can restart..."
Start you project : Click on the ".Rproj"
file in your project directory.
Files pane > More > Show Hidden Files
remotes::install_github('rstudio/renv')
# Should already be done # install.packages("usethis") usethis::use_git_ignore("renv_instructions.Rmd") usethis::use_build_ignore("renv_instructions.Rmd")
# Project library position: # This is default, uncomment is not necessary. # Sys.setenv(RENV_PATHS_LIBRARY_ROOT = "renv/library") # However, if you set library out of the project, # change in accordance with `renv_out = TRUE` then use: # Sys.setenv(RENV_PATHS_LIBRARY_ROOT = "~/.renv/library") renv::consent(TRUE) # Open the Console to answer question to proceed renv::activate()
# Set up cache Sys.setenv(RENV_PATHS_CACHE = "/opt/local/renv/cache") renv::settings$use.cache(TRUE) # Install {renv} in global cache renv::install("renv")
Store the following code inside your project .Rprofile
file to reduce problems with cache (Open .Rprofile with: usethis::edit_r_profile(scope = "project")
).
Add code in this order:
# If you have a user .Rprofile inside the container, you may want to uncomment this # source("~/.Rprofile") # Project library position: # This is default, uncomment is not necessary. # Sys.setenv(RENV_PATHS_LIBRARY_ROOT = "renv/library") # However, if you set library out of the project, # change in accordance with `renv_out = TRUE` then use: # Sys.setenv(RENV_PATHS_LIBRARY_ROOT = "~/.renv/library") source("renv/activate.R") renv::activate() # cache ---- if (dir.exists("/opt/local/renv/cache")) { # Cache inside the docker container with persistent drive # shared on host Sys.setenv(RENV_PATHS_CACHE = "/opt/local/renv/cache") renv::settings$use.cache(TRUE) } else { # No cache renv::settings$use.cache(FALSE) }
Restart your RStudio session
Do not worry now about different {renv} versions
End of initialization. Then you can have a look at following commands for dev.
Follow instructions of {renv} in your Console. This might be running:
renv::snapshot()
This is due to the change of the global cache. You will need to re-install packages as follows:
ll <- list.files(.libPaths()[1], full.names = FALSE) for (l in ll) { try(install.packages(l)) }
Restart your Rstudio session. There should not be anymore symlinks problems.
Try again to stop the RStudio session, stop the container and relaunch to verify installation.
renv::init()
Prefer using renv::install()
for your package installations to be sure it uses the global {renv} cache et symbolic links.
# From doc: ?renv::install # install the latest version of 'digest' on CRAN renv::install("digest") # install an old version of 'digest' (using CRAN archives) renv::install("digest@0.6.18") # install 'digest' from GitHub (latest dev. version) renv::install("eddelbuettel/digest") # install a package from GitHub, using specific commit renv::install("eddelbuettel/digest@df55b00bff33e945246eff2586717452e635032f") # install a package from Bioconductor # (note: requires the BiocManager package) renv::install("bioc::Biobase") # install from gitlab.com renv::install("gitlab::jimhester/covr") # install from random git renv::install("git::git@bitbucket.org:djnavarro/lsr.git") # install a package from local sources renv::install("~/path/to/package")
If you are satisfied with the effects, run:
renv::snapshot()
Note that you may want to limit the number of packages added in the lockfile to the one listed in your DESCRIPTION file. To do so, you can use:
renv::snapshot(type = "explicit")
But in you are in the process of package development, you may want to also share versions of packages like {devtools}, {roxygen2}, {usethis}, {testthat}, {covr}, {attachment}, ...
As well as {renv} itself.
In this case, you can use the package
parameter :
# Update DESCRIPTION file attachment::att_amend_desc() # List dependencies custom_packages <- c(attachment::att_from_description(), "renv", "knitr", "devtools", "roxygen2", "usethis", "testthat", "covr", "attachment", "pkgdown") # Snapshot renv::snapshot(packages = custom_packages)
If you are not satisfied, run:
renv::restore() # instead of snapshot()
And after you ran devtools::check()
, store your packages list with:
renv::snapshot() # or only those in DESCRIPTION with renv::snapshot(type = "explicit") # OR packages in DESCRIPTION + development utilities attachment::att_amend_desc() custom_packages <- c(attachment::att_from_description(), "renv", "knitr", "devtools", "roxygen2", "usethis", "testthat", "covr", "attachment", "pkgdown") renv::snapshot(packages = custom_packages)
There may be new packages needed, therefore run:
renv::restore()
This should normally be automatically done in the renv/activate.R
, but you can do it with:
renv::upgrade()
lock <- renv:::lockfile("renv.lock") # set the repositories for a lockfile # All CRAN : "https://cloud.r-project.org" # Fixed MRAN example: "https://mran.revolutionanalytics.com/snapshot/2019-08-05" # Fixed CRAN date example, allowing for Linux binaries: "https://packagemanager.rstudio.com/all/308" # Latest CRAN repository allowing for Linux binaries: "https://packagemanager.rstudio.com/all/latest" lock$repos(CRAN = "https://packagemanager.rstudio.com/all/latest") # write to file lock$write("renv.lock") # Update your packages update.packages()
Depending on the repos you chose, you may not be able to choose a specific package version. Instead use:
remotes::install_version("golem", version = "0.3.0", repos = "https://cloud.r-project.org")
# project config usethis::use_git_config(scope = "project", user.name = "username", user.email = "user@email.fr")
Must be done for each session as not stored in the persistent drive
# Store credentials my_cred <- git2r::cred_user_pass( username = "username", password = askpass::askpass() ) usethis::use_git_credentials(credentials = my_cred)
You may have to be sure to install dependencies from MRAN
ll <- list.files(.libPaths()[1], full.names = TRUE) for (l in ll) { try(remotes::install_cran(l)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.