renv doesn't persist between RStudio sessions

I have an RStudio project that uses renv. I recently upgraded my core R version, and had to reinstall the packages from the original lockfile. Now each time I open the project I get this message:

Using R 4.4.2 (lockfile was generated with R 4.3.1)
- Project {my_project} loaded. [renv 1.0.11]
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.

When I explore my_project/renv/library... I see all the packages duly sitting there.

How can I make RStudio / renv recognise the packages are already installed, rather than reinstalling them all each time I open the project?

Can you please provide more information? What does renv::status() report? What about renv::diagnostics()?

Hi @kevinushey,

renv::status() lists the inconsistent packages e.g. askpass is supposedly recorded but not installed:

package           installed recorded used
 askpass           n         y        ?   

But then I inspect the library and askpass has a folder just as it should...

renv::diagnostics() provides the same list of packages in an "inconsistent state", followed by a list of packages where Library and Source shows as NA, while Lockfile shows the version, like this:

# Packages -------------------------------------------------------------------
                  Library Source Lockfile Source Path Dependency
DBI                  <NA>   <NA>    1.2.3   RSPM <NA>       <NA>

Again, I can locate all of these in the local renv library folder for R4.4

Does find.package("askpass") also report that the version in your renv library is loaded and used?

Can you please share the entirety of the renv::diagnostics() output? You can use https://gist.github.com/ if the file is large.

No, find.package("askpass") agrees with renv::status() that the package is not installed:

Error in find.package("askpass") : there is no package called ‘askpass’

Here is the output of renv::diagnostics():

Diagnostics Report [renv 1.0.11]
================================


# Session Info ---------------------------------------------------------------
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8 
[2] LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.4.2 tools_4.4.2    renv_1.0.11   

# Project --------------------------------------------------------------------
Project path: REDACTED = PROJECT_FOLDER below

# Status ---------------------------------------------------------------------
The following package(s) are in an inconsistent state:

 package           installed recorded used
 askpass           n         y        ?   
 base64enc         n         y        ?   
 bit               n         y        ?   
 bit64             n         y        ?   
 blob              n         y        ?   
 bslib             n         y        ?   
 cachem            n         y        ?   
 cellranger        n         y        ?   
 class             y         y        ?   
 classInt          n         y        ?   
 cli               n         y        ?   
 colorspace        n         y        ?   
 commonmark        n         y        ?   
 cpp11             n         y        ?   
 crayon            n         y        ?   
 crosstalk         n         y        ?   
 curl              n         y        ?   
 data.table        n         y        ?   
 DBI               n         y        ?   
 digest            n         y        ?   
 dplyr             n         y        y   
 e1071             n         y        ?   
 ellipsis          n         y        ?   
 evaluate          n         y        ?   
 fansi             n         y        ?   
 farver            n         y        ?   
 fastmap           n         y        ?   
 fontawesome       n         y        ?   
 fs                n         y        ?   
 generics          n         y        ?   
 ggplot2           n         y        y   
 glue              n         y        ?   
 gtable            n         y        ?   
 highr             n         y        ?   
 hms               n         y        ?   
 htmltools         n         y        ?   
 htmlwidgets       n         y        ?   
 httpuv            n         y        ?   
 httr              n         y        y   
 isoband           n         y        ?   
 jquerylib         n         y        ?   
 jsonlite          n         y        y   
 KernSmooth        y         y        ?   
 knitr             n         y        ?   
 labeling          n         y        ?   
 later             n         y        ?   
 lattice           y         y        ?   
 lazyeval          n         y        ?   
 leaflet           n         y        y   
 leaflet.providers n         y        ?   
 lifecycle         n         y        ?   
 logger            n         y        y   
 lubridate         n         y        y   
 magrittr          n         y        ?   
 markdown          n         y        y   
 MASS              y         y        ?   
 Matrix            y         y        ?   
 memoise           n         y        ?   
 mgcv              y         y        ?   
 mime              n         y        ?   
 munsell           n         y        ?   
 nlme              y         y        ?   
 openssl           n         y        ?   
 pillar            n         y        ?   
 pins              n         y        y   
 pkgconfig         n         y        ?   
 plogr             n         y        ?   
 plotly            n         y        y   
 png               n         y        ?   
 prettyunits       n         y        ?   
 progress          n         y        ?   
 promises          n         y        ?   
 proxy             n         y        ?   
 purrr             n         y        ?   
 R6                n         y        ?   
 rappdirs          n         y        ?   
 raster            n         y        ?   
 RColorBrewer      n         y        ?   
 Rcpp              n         y        ?   
 readxl            n         y        y   
 rematch           n         y        ?   
 rlang             n         y        ?   
 rmarkdown         n         y        ?   
 RPostgres         n         y        y   
 s2                n         y        ?   
 sass              n         y        ?   
 scales            n         y        y   
 sf                n         y        y   
 shiny             n         y        y   
 shinyauthr        n         y        y   
 shinyjs           n         y        ?   
 shinyWidgets      n         y        y   
 showtext          n         y        y   
 showtextdb        n         y        ?   
 sodium            n         y        ?   
 sourcetools       n         y        ?   
 sp                n         y        ?   
 stringi           n         y        ?   
 stringr           n         y        ?   
 sys               n         y        ?   
 sysfonts          n         y        ?   
 terra             n         y        ?   
 tibble            n         y        ?   
 tidyr             n         y        y   
 tidyselect        n         y        ?   
 timechange        n         y        ?   
 tinytex           n         y        ?   
 units             n         y        ?   
 utf8              n         y        ?   
 vctrs             n         y        ?   
 viridisLite       n         y        ?   
 whisker           n         y        ?   
 withr             n         y        ?   
 wk                n         y        ?   
 xfun              n         y        ?   
 xtable            n         y        ?   
 yaml              n         y        ?   

The following package(s) are out of sync [lockfile != library]:

# CRAN -----------------------------------------------------------------------
- KernSmooth   [2.23-21 != 2.23-24]
- lattice      [0.21-8 != 0.22-6]
- MASS         [7.3-60 != 7.3-61]
- Matrix       [1.5-4.1 != 1.7-1]
- mgcv         [1.8-42 != 1.9-1]
- nlme         [3.1-162 != 3.1-166]

The lockfile was generated with R 4.3.2, but you're using R 4.4.2.

See `?renv::status` for advice on resolving these issues.

# Packages -------------------------------------------------------------------
                  Library Source Lockfile Source Path Dependency
DBI                  <NA>   <NA>    1.2.3   RSPM <NA>       <NA>
KernSmooth        2.23-24   CRAN  2.23-21   CRAN  [2]       <NA>
MASS               7.3-61   CRAN   7.3-60   CRAN  [2]       <NA>
Matrix              1.7-1   CRAN  1.5-4.1   CRAN  [2]       <NA>
R6                   <NA>   <NA>    2.5.1   CRAN <NA>       <NA>
RColorBrewer         <NA>   <NA>    1.1-3   CRAN <NA>       <NA>
RPostgres            <NA>   <NA>    1.4.7   CRAN <NA>     direct
Rcpp                 <NA>   <NA>   1.0.11   CRAN <NA>       <NA>
askpass              <NA>   <NA>    1.2.1   RSPM <NA>       <NA>
base64enc            <NA>   <NA>    0.1-3   CRAN <NA>       <NA>
bit                  <NA>   <NA>    4.0.5   CRAN <NA>       <NA>
bit64                <NA>   <NA>    4.0.5   CRAN <NA>       <NA>
blob                 <NA>   <NA>    1.2.4   CRAN <NA>       <NA>
boot               1.3-31   CRAN     <NA>   <NA>  [2]       <NA>
bslib                <NA>   <NA>    0.5.1   CRAN <NA>       <NA>
cachem               <NA>   <NA>    1.0.8   CRAN <NA>       <NA>
cellranger           <NA>   <NA>    1.1.0   CRAN <NA>       <NA>
class              7.3-22   CRAN   7.3-22   CRAN  [2]       <NA>
classInt             <NA>   <NA>   0.4-10   CRAN <NA>       <NA>
cli                  <NA>   <NA>    3.6.3   RSPM <NA>       <NA>
cluster             2.1.6   CRAN     <NA>   <NA>  [2]       <NA>
codetools          0.2-20   CRAN     <NA>   <NA>  [2]       <NA>
colorspace           <NA>   <NA>    2.1-0   CRAN <NA>       <NA>
commonmark           <NA>   <NA>    1.9.2   RSPM <NA>       <NA>
cpp11                <NA>   <NA>    0.5.0   RSPM <NA>       <NA>
crayon               <NA>   <NA>    1.5.3   RSPM <NA>       <NA>
crosstalk            <NA>   <NA>    1.2.0   CRAN <NA>       <NA>
curl                 <NA>   <NA>    5.2.3   RSPM <NA>       <NA>
data.table           <NA>   <NA>   1.15.2   CRAN <NA>       <NA>
digest               <NA>   <NA>   0.6.33   CRAN <NA>       <NA>
dplyr                <NA>   <NA>    1.1.4   CRAN <NA>     direct
e1071                <NA>   <NA>   1.7-14   CRAN <NA>       <NA>
ellipsis             <NA>   <NA>    0.3.2   CRAN <NA>       <NA>
evaluate             <NA>   <NA>    1.0.1   RSPM <NA>       <NA>
fansi                <NA>   <NA>    1.0.4   CRAN <NA>       <NA>
farver               <NA>   <NA>    2.1.2   CRAN <NA>       <NA>
fastmap              <NA>   <NA>    1.1.1   CRAN <NA>       <NA>
fontawesome          <NA>   <NA>    0.5.2   CRAN <NA>       <NA>
foreign            0.8-87   CRAN     <NA>   <NA>  [2]       <NA>
fs                   <NA>   <NA>    1.6.4   RSPM <NA>       <NA>
generics             <NA>   <NA>    0.1.3   CRAN <NA>       <NA>
ggplot2              <NA>   <NA>    3.5.0   CRAN <NA>     direct
glue                 <NA>   <NA>    1.6.2   CRAN <NA>       <NA>
gtable               <NA>   <NA>    0.3.4   CRAN <NA>       <NA>
highr                <NA>   <NA>     0.11   RSPM <NA>       <NA>
hms                  <NA>   <NA>    1.1.3   CRAN <NA>       <NA>
htmltools            <NA>   <NA>    0.5.6   CRAN <NA>       <NA>
htmlwidgets          <NA>   <NA>    1.6.2   CRAN <NA>       <NA>
httpuv               <NA>   <NA>   1.6.15   CRAN <NA>       <NA>
httr                 <NA>   <NA>    1.4.7   CRAN <NA>     direct
isoband              <NA>   <NA>    0.2.7   CRAN <NA>       <NA>
jquerylib            <NA>   <NA>    0.1.4   CRAN <NA>       <NA>
jsonlite             <NA>   <NA>    1.8.7   CRAN <NA>     direct
knitr                <NA>   <NA>     1.48   RSPM <NA>       <NA>
labeling             <NA>   <NA>    0.4.3   CRAN <NA>       <NA>
later                <NA>   <NA>    1.3.1   CRAN <NA>       <NA>
lattice            0.22-6   CRAN   0.21-8   CRAN  [2]       <NA>
lazyeval             <NA>   <NA>    0.2.2   CRAN <NA>       <NA>
leaflet              <NA>   <NA>    2.2.2   CRAN <NA>     direct
leaflet.providers    <NA>   <NA>    2.0.0   CRAN <NA>       <NA>
lifecycle            <NA>   <NA>    1.0.3   CRAN <NA>       <NA>
logger               <NA>   <NA>    0.4.0   CRAN <NA>     direct
lubridate            <NA>   <NA>    1.9.3   CRAN <NA>     direct
magrittr             <NA>   <NA>    2.0.3   CRAN <NA>       <NA>
markdown             <NA>   <NA>     1.13   RSPM <NA>     direct
memoise              <NA>   <NA>    2.0.1   CRAN <NA>       <NA>
mgcv                1.9-1   CRAN   1.8-42   CRAN  [2]       <NA>
mime                 <NA>   <NA>     0.12   CRAN <NA>       <NA>
munsell              <NA>   <NA>    0.5.0   CRAN <NA>       <NA>
nlme              3.1-166   CRAN  3.1-162   CRAN  [2]       <NA>
nnet               7.3-19   CRAN     <NA>   <NA>  [2]       <NA>
openssl              <NA>   <NA>    2.2.2   RSPM <NA>       <NA>
pillar               <NA>   <NA>    1.9.0   CRAN <NA>       <NA>
pins                 <NA>   <NA>    1.4.0   RSPM <NA>     direct
pkgconfig            <NA>   <NA>    2.0.3   CRAN <NA>       <NA>
plogr                <NA>   <NA>    0.2.0   CRAN <NA>       <NA>
plotly               <NA>   <NA>   4.10.4   CRAN <NA>     direct
png                  <NA>   <NA>    0.1-8   CRAN <NA>       <NA>
prettyunits          <NA>   <NA>    1.2.0   CRAN <NA>       <NA>
progress             <NA>   <NA>    1.2.3   CRAN <NA>       <NA>
promises             <NA>   <NA>    1.2.1   RSPM <NA>       <NA>
proxy                <NA>   <NA>   0.4-27   CRAN <NA>       <NA>
purrr                <NA>   <NA>    1.0.2   CRAN <NA>       <NA>
rappdirs             <NA>   <NA>    0.3.3   CRAN <NA>       <NA>
raster               <NA>   <NA>   3.6-30   CRAN <NA>       <NA>
readxl               <NA>   <NA>    1.4.3   CRAN <NA>     direct
rematch              <NA>   <NA>    2.0.0   CRAN <NA>       <NA>
renv               1.0.11   CRAN   1.0.11   RSPM  [1]     direct
rlang                <NA>   <NA>    1.1.4   RSPM <NA>       <NA>
rmarkdown            <NA>   <NA>     2.28   RSPM <NA>       <NA>
rpart              4.1.23   CRAN     <NA>   <NA>  [2]       <NA>
s2                   <NA>   <NA>    1.1.7   RSPM <NA>       <NA>
sass                 <NA>   <NA>    0.4.7   CRAN <NA>       <NA>
scales               <NA>   <NA>    1.3.0   CRAN <NA>     direct
sf                   <NA>   <NA>   1.0-18   CRAN <NA>     direct
shiny                <NA>   <NA>  1.8.1.1   RSPM <NA>     direct
shinyWidgets         <NA>   <NA>    0.8.7   CRAN <NA>     direct
shinyauthr           <NA>   <NA>    1.0.0   RSPM <NA>     direct
shinyjs              <NA>   <NA>    2.1.0   RSPM <NA>       <NA>
showtext             <NA>   <NA>    0.9-7   RSPM <NA>     direct
showtextdb           <NA>   <NA>      3.0   RSPM <NA>       <NA>
sodium               <NA>   <NA>    1.3.2   CRAN <NA>       <NA>
sourcetools          <NA>   <NA>  0.1.7-1   CRAN <NA>       <NA>
sp                   <NA>   <NA>    2.1-4   CRAN <NA>       <NA>
spatial            7.3-17   CRAN     <NA>   <NA>  [2]       <NA>
stringi              <NA>   <NA>    1.8.4   RSPM <NA>       <NA>
stringr              <NA>   <NA>    1.5.1   CRAN <NA>       <NA>
survival            3.7-0   CRAN     <NA>   <NA>  [2]       <NA>
sys                  <NA>   <NA>    3.4.3   RSPM <NA>       <NA>
sysfonts             <NA>   <NA>    0.8.9   RSPM <NA>       <NA>
terra                <NA>   <NA>   1.7-83   CRAN <NA>       <NA>
tibble               <NA>   <NA>    3.2.1   CRAN <NA>       <NA>
tidyr                <NA>   <NA>    1.3.1   CRAN <NA>     direct
tidyselect           <NA>   <NA>    1.2.1   CRAN <NA>       <NA>
timechange           <NA>   <NA>    0.3.0   CRAN <NA>       <NA>
tinytex              <NA>   <NA>     0.53   RSPM <NA>       <NA>
units                <NA>   <NA>    0.8-5   CRAN <NA>       <NA>
utf8                 <NA>   <NA>    1.2.3   CRAN <NA>       <NA>
utils                <NA>   <NA>     <NA>   <NA>  [2]   indirect
vctrs                <NA>   <NA>    0.6.5   CRAN <NA>       <NA>
viridisLite          <NA>   <NA>    0.4.2   CRAN <NA>       <NA>
whisker              <NA>   <NA>    0.4.1   RSPM <NA>       <NA>
withr                <NA>   <NA>    2.5.1   RSPM <NA>       <NA>
wk                   <NA>   <NA>    0.9.4   CRAN <NA>       <NA>
xfun                 <NA>   <NA>     0.48   RSPM <NA>       <NA>
xtable               <NA>   <NA>    1.8-4   CRAN <NA>       <NA>
yaml                 <NA>   <NA>   2.3.10   RSPM <NA>       <NA>

[1]: PROJECT_FOLDER/renv/library/windows/R-4.4/x86_64-w64-mingw32                  
[2]: SYSTEM_FOLDER/AppData/Local/R/cache/R/renv/sandbox/windows/R-4.4/x86_64-w64-mingw32/d974eb96

# ABI ------------------------------------------------------------------------
- ABI conflict checks are not available on Windows.

# User Profile ---------------------------------------------------------------
[no user profile detected]

# Settings -------------------------------------------------------------------
List of 13
 $ bioconductor.version     : NULL
 $ external.libraries       : chr(0) 
 $ ignored.packages         : chr(0) 
 $ package.dependency.fields: chr [1:3] "Imports" "Depends" "LinkingTo"
 $ ppm.enabled              : NULL
 $ ppm.ignored.urls         : chr(0) 
 $ r.version                : NULL
 $ snapshot.type            : chr "implicit"
 $ use.cache                : logi TRUE
 $ vcs.ignore.cellar        : logi TRUE
 $ vcs.ignore.library       : logi TRUE
 $ vcs.ignore.local         : logi TRUE
 $ vcs.manage.ignores       : logi TRUE

# Options --------------------------------------------------------------------
List of 8
 $ defaultPackages                     : chr [1:6] "datasets" "utils" "grDevices" "graphics" ...
 $ download.file.method                : chr "libcurl"
 $ download.file.extra                 : NULL
 $ install.packages.compile.from.source: chr "interactive"
 $ pkgType                             : chr "both"
 $ repos                               : Named chr "https://packagemanager.posit.co/cran/latest"
  ..- attr(*, "names")= chr "CRAN"
 $ renv.consent                        : logi TRUE
 $ renv.verbose                        : logi TRUE

# Environment Variables ------------------------------------------------------
REDACTED

# PATH -----------------------------------------------------------------------
REDACTED

# Cache ----------------------------------------------------------------------
There are a total of 205 packages installed in the renv cache.
Cache path: "SYSTEM_FOLDER/AppData/Local/R/cache/R/renv/cache/v5/windows/R-4.4/x86_64-w64-mingw32"

Hello @kevinushey - little nudge on the above - what does the renv::diagnostics output tell you?

Unfortunately, not much. This issue feels similar to this one, though:

Does that sound familiar?

No it doesn't @kevinushey

They say "Package can be installed in renv project library and be used (e.g. with library() or in the code itself)" - but as I said, I can't use the packages. Sounds like they have a UNIX permissions issue, but we're just on vanilla Windows so I don't think it can be relevant.

I should also underline this is only an issue when the base version of R in use does not match the one used to create the renv.

Any ideas on how to fix, or you think this is a new bug discovery?

@kevinushey did you have any thoughts on this?