/
pak-sitrep.R
131 lines (118 loc) · 3.15 KB
/
pak-sitrep.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#' pak SITuation REPort
#'
#' It prints
#' * pak version,
#' * platform the package was built on, and the current platform,
#' * the current library path,
#' * versions of dependencies,
#' * whether dependencies can be loaded.
#'
#' @export
#' @family pak housekeeping
#' @section Examples:
#' ```{asciicast pak-sitrep}
#' pak_sitrep()
#' ```
pak_sitrep <- function() {
## version
ver <- as.character(utils::packageVersion("pak"))
cat0("* pak version:\n- ", ver, "\n")
## platform data
ver <- pak_sitrep_data
plt <- R.Version()$platform
comp <- platform_match(ver$platform, plt)
cat0("* Version information:\n")
cat0(
"- pak platform: ", ver$platform,
" (current: ", R.Version()$platform, if (comp) ", compatible", ")\n"
)
if (!comp) cat0("- platform is incompatible!\n")
repo <- ver$`github-repository`
sha <- ver$`github-sha`
if (repo != "r-lib/pak") {
cat0(
"- pak repository: ", repo,
if (repo == "-") " (local install?)",
"\n"
)
}
if (repo != "-" || sha != "-") cat0("- pak sha: ", sha, "\n")
## recommended packages
xpkgs <- extra_packages()
if (length(xpkgs)) {
xinst <- pkg_is_installed(xpkgs)
if (any(xinst)) {
cat0("* Optional packages installed:\n")
cat0(paste0("- ", xpkgs[xinst], "\n"))
}
if (any(!xinst)) {
cat0("* Optional packages missing:\n")
cat0(paste0("- ", xpkgs[!xinst], "\n"))
}
}
## library path
cat0("* Library path:\n")
cat(paste0("- ", .libPaths()), sep = "\n")
lib <- private_lib_dir()
if (!is.null(asNamespace("pak")[[".__DEVTOOLS__"]])) {
cat0("* Using `load_all()` from ", find.package("pak"), ".\n")
cat0("* Private library location:\n- ", lib, "\n")
} else {
cat0("* pak is installed at ", find.package("pak"), ".\n")
}
dver <- pak_library_versions(lib)
cat0("* Dependency versions:\n")
cat0(paste0(
"- ",
format(dver$package),
" ",
format(dver$version),
ifelse(is.na(dver$sha), "", paste0(" (", substr(dver$sha, 1, 7), ")")),
"\n"
))
ret <- tryCatch(
{
new_remote_session()
# TODO: check that all packages can be loaded in subprocess
TRUE
},
error = function(e) e
)
if (isTRUE(ret)) {
cat0("* Dependencies can be loaded\n")
} else {
cat("! Could not load dependencies, pak installation is broken. :(\n")
cat0("Error: ", conditionMessage(ret))
}
invisible()
}
pak_library_versions <- function(lib) {
pkgs <- dir(lib)
vers <- lapply(pkgs, function(pkg) get_ver(file.path(lib, pkg)))
data.frame(
stringsAsFactors = FALSE,
package = pkgs,
version = vcapply(vers, "[", 1),
sha = vcapply(vers, "[", 2)
)
}
# this is slightly different than the one in install-embedded.R
get_ver <- function(path) {
if (!file.exists(path)) {
return(NA_character_)
}
desc <- file.path(path, "DESCRIPTION")
if (!file.exists(desc)) {
return(NA_character_)
}
dsc <- read.dcf(desc)
ver <- package_version(dsc[, "Version"])
devver <- as.numeric(ver[1, 4])
if (!is.na(devver) && devver >= 9000) {
if ("RemoteSha" %in% colnames(dsc)) {
sha <- dsc[, "RemoteSha"]
return(c(ver, sha))
}
}
as.character(ver)
}