Skip to content

Commit

Permalink
status reports used but unrecorded / uninstalled packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Jan 12, 2021
1 parent 8b08511 commit 7bd669b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: renv
Type: Package
Title: Project Environments
Version: 0.12.5-6
Version: 0.12.5-7
Authors@R: c(
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]"),
person("RStudio", role = c("cph"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# renv 0.13.0 (UNRELEASED)

* `renv::status()` now reports packages that are referenced in a project's
scripts, but are neither installed in the project library nor recorded in the
lockfile. (#588)

* Fixed an issue where package installation could fail if the `configure.vars`
option was set to be a named character, rather than a named list. (#609)

Expand Down
15 changes: 12 additions & 3 deletions R/status.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ renv_status_impl <- function(project, libpaths, lockpath, cache) {
)

renv_status_check_unknown_sources(project, lockfile)
renv_status_check_used_packages(project, lockfile, libstate)

if (cache)
renv_status_check_cache(project)
Expand Down Expand Up @@ -108,16 +109,21 @@ renv_status_check_missing_library <- function(project, libpaths) {

}

renv_status_check_used_packages <- function(project, libstate) {
renv_status_check_used_packages <- function(project, lockfile, libstate) {

# only done when using implicit snapshots in a project
type <- settings$snapshot.type(project = project)
if (!type %in% c("implicit", "packrat"))
return(FALSE)

deps <- dependencies(project, progress = FALSE)
used <- sort(unique(deps$Package))
records <- renv_records(libstate)

ignored <- c(
renv_packages_base(),
renv_project_ignored_packages(project),
names(records)
names(renv_records(lockfile)),
names(renv_records(libstate))
)

missing <- setdiff(used, ignored)
Expand All @@ -134,6 +140,9 @@ renv_status_check_used_packages <- function(project, libstate) {
wrap = FALSE
)

if (renv_tests_running())
renv_condition_signal("renv.status.used_but_not_installed", missing)

FALSE

}
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-status.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ test_that("status reports packages to be installed / changed", {
snapshot()

})

test_that("status reports packages which are used but not installed", {

renv_tests_scope()
renv_scope_sink()
init()

writeLines("library(bread)", con = "script.R")
expect_signal(status(), class = "renv.status.used_but_not_installed")

})

0 comments on commit 7bd669b

Please sign in to comment.