renv installs inproper version of package

Hello everyone,
it is so sill problem, that I guess, I miss something.

So I have nothing at beginning:

"C:/Users/x/Documents/R/win-library/3.6" "C:/Program Files/R/R-3.6.1/library"

In C:/Program Files/R/R-3.6.1/library I've got default packages, and empty personal library.

Then I have source of my package with DESCRIPTION:

Package: x
Type: Package
Title: x
Version: 0.3.9006
License: MIT
Encoding: UTF-8
LazyData: true
Depends: R (>= 3.0.0)
  rlang (<= 0.3.4)
RoxygenNote: 6.1.1

and .renvignore with ignored everything except this DESCRIPTION file.

With that I run in R (3.6.1):

install.packages('renv') # it's installed to my personal library
> Finding R package dependencies ... Done!
                                Source Package Require Version   Dev
> 3 C:/Users/x/Desktop/x/x/x/DESCRIPTION       R      >=   3.0.0 FALSE
> 4 C:/Users/x/Desktop/x/x/x/DESCRIPTION   rlang      <=   0.3.4 FALSE

it's clear that I wants rlang 0.3.4.
Then I run:

r$> renv::init()
* Discovering package dependencies ... Done!
* Copying packages into the cache ... Done!
The following package(s) will be updated in the lockfile:

# CRAN ===============================
- rlang   [* -> 0.4.2]

* Lockfile written to 'C:/Users/x/Desktop/x/x/renv.lock'.
* Project 'C:/Users/x/Desktop/x/x' loaded. [renv 0.8.3]
* renv activated -- please restart the R session.

And as you can see I get rlang 0.4.2.

How I can get version of packages, that I have in requirements?

renv::init() does not look at package versions in the DESCRIPTION file when deciding what to install. It simply forks the state of your current user library, giving you an isolated "clone" of the current state of your user library.

You can use renv::install() to instead install packages respecting requirements declared in the DESCRIPTION file, although note that you might need to request a specific version with e.g.

rlang (== 0.3.4)

Kevin, thank you so much for your reply.
But I start with empty library, I have rlang installed nowhere, and then init tries to install it, so I guess it looks into DESCRIPTION (this is only place where I have rlang mentioned)

And by the way, I guess I cannot run renv::install() in a way that will install for me all packages in DESCRIPTION in specified versions?

That's correct. In effect, right now, renv::init() works in the following way:

  1. Packages used within the project are discovered (including, as you're seeing, by examining the DESCRIPTION file);

  2. Any mentioned packages are 'cloned' from the user library into the project library;

  3. Any missing packages are installed from CRAN (if possible).

Perhaps the behavior here should change for projects which have a DESCRIPTION file, though. I'm still a little torn on what the correct behavior is.

That said, calling


without any arguments should, in theory, work.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.