lo labs
lo labs

Reputation: 159

How to change R repository CRAN from renv.lock to get packages from an internal/corporate repository?

I will let an R project run on a data center and the team working there has no access to the Internet, so they will have to download the R libraries from an internal repository (on their Intranet) where all the packages are hosted.

  1. It is possible to change the repository from where the libraries are downloaded?
  2. and how can we point to this repository if I will provide them with my renv.lock file?

Could be solved by doing this? :

repos <- c(CRAN = "https://cloud.r-project.org", WORK = "https://work.example.org")
options(repos = repos)

See here

Thanks a lot

Upvotes: 8

Views: 3891

Answers (2)

BSCowboy
BSCowboy

Reputation: 357

I found myself in the situation where my private repos were set, but whenever I ran renv::init(), it wouldn't point to them. The simplest solution I could come up with from reading the renv docs:

  1. Before calling renv::init(), call the function: Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE").
  2. If it returns anything other than the URL to your private package repository then call the function: Sys.setenv("RENV_CONFIG_REPOS_OVERRIDE" = "your_private_package_repository_url")
  3. Call the function renv::init()

Upvotes: 4

Kevin Ushey
Kevin Ushey

Reputation: 21315

  1. It is possible to change the repository from where the libraries are downloaded?

Yes, and the example code you shared is correct: the active package repositories used in an R session are controlled via the repos option.

  1. and how can we point to this repository if I will provide them with my renv.lock file?

If you're working within an renv project with an auto-loader, then renv will automatically set the repositories from the lockfile when R is started. Otherwise, you can call renv::load("/path/to/project") to explicitly load a project at some location.

I'd recommend reading https://rstudio.github.io/renv/articles/renv.html for more details.

Upvotes: 4

Related Questions