Skip to content

Commit

Permalink
Only get namespace versions for loaded namespaces. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester authored and gaborcsardi committed Aug 2, 2017
1 parent 8de1163 commit be05f95
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- `session_info()` now only lists loaded versions for namespaces which are already loaded.

# 0.0.0.9000

Expand Down
5 changes: 4 additions & 1 deletion R/dependent-packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ dependent_packages <- function(pkgs) {
pkgs <- find_deps(pkgs, utils::installed.packages(), top_dep = NA)
desc <- lapply(pkgs, utils::packageDescription)

loaded_pkgs <- pkgs %in% setdiff(loadedNamespaces(), "base")
loadedversion <- rep(NA_character_, length(pkgs))
loadedversion[loaded_pkgs] <- vapply(pkgs[loaded_pkgs], getNamespaceVersion, "")
res <- data.frame(
package = pkgs,
ondiskversion = vapply(desc, function(x) x$Version, character(1)),
loadedversion = vapply(pkgs, getNamespaceVersion, ""),
loadedversion = loadedversion,
path = vapply(desc, pkg_path, character(1)),
attached = paste0("package:", pkgs) %in% search(),
stringsAsFactors = FALSE,
Expand Down
7 changes: 5 additions & 2 deletions R/package-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ pkg_source <- function(desc) {

print.packages_info <- function(x, ...) {

badloaded <- package_version(x$loadedversion) !=
unloaded <- is.na(x$loadedversion)
badloaded <- package_version(x$loadedversion, strict = FALSE) !=
package_version(x$ondiskversion)

px <- data.frame(
package = x$package,
"*" = ifelse(x$attached, "*", ""),
version = paste0(x$loadedversion, ifelse(badloaded, " (!)", "")),
version = ifelse(unloaded,
x$ondiskversion,
paste0(x$loadedversion, ifelse(badloaded, " (!)", ""))),
date = x$date,
source = x$source,
stringsAsFactors = FALSE,
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-dependent-packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ test_that("dependent_packages", {
'utils::packageDescription',
function(x) alldsc[[x]]
)
mockery::stub(
dependent_packages,
'base::loadedNamespaces',
function() ins
)

mockery::stub(
dependent_packages,
'getNamespaceVersion',
Expand Down

0 comments on commit be05f95

Please sign in to comment.