Description
Currently, the r-packages repository has a list of instructions for installing non-CRAN Stan packages like {cmdstanr} (see here for the live version).
It includes instructions for adding https://mc-stan.org/r-packages/
as a named repository for use with {renv}, either by using options()
, or by manually adding an entry to renv.lock
.
Since {renv} v1.0 (ish), having a second named repository in renv.lock
triggers a "The project is out-of-sync" message even if the correct version of packages like {cmdstanr} are installed. See this issue at {renv} for more details, or see this reproducible example (starting from a new empty project):
# Start a new renv library
renv::init()
# Add Stan's repo as a valid source
repos <- c(Stan = "https://mc-stan.org/r-packages/", CRAN = "https://packagemanager.posit.co/cran/latest")
options(repos = repos)
# Install cmdstanr; it will come from the Stan repo; all other dependencies will come from CRAN/RSPM
install.packages("cmdstanr")
# Save to lockfile
renv::snapshot()
# Make sure everything is good
renv::status()
#> No issues found -- the project is in a consistent state.
# RESTART R SESSION
#> Restarting R session...
#>
#> - Project '~/Desktop/renv-testing' loaded. [renv 1.0.2.9000; sha: dba0079]
#> - The project is out-of-sync -- use `renv::status()` for details.
# It says it's out of sync there ↑
# But if I run renv::status() again, all is well
renv::status()
#> No issues found -- the project is in a consistent state.
According to @kevinushey (rstudio/renv#1683 (comment)), this happens because even though https://mc-stan.org/r-packages/
is a named repository, {renv} checks for a "Repository" entry each package's DESCRIPTION file, and {cmdstanr} doesn't have that in its DESCRIPTION.
It's possible to fix this false positive warning by adding a "Repository" entry to DESCRIPTION:
Repository: Stan
It seems like a trivial enough change, but I don't know what the downstream consequences of doing that might be (so I'm opening an issue rather than making an actual pull request). The "Repository" entry isn't well documented so I don't know if it will mess things up, but it might be worth adding to non-CRAN packages like {cmdstanr} for better compatibility with {renv}.