forked from REditorSupport/vscode-R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAliases.R
More file actions
43 lines (36 loc) · 960 Bytes
/
Copy pathgetAliases.R
File metadata and controls
43 lines (36 loc) · 960 Bytes
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
add_lib_paths <- Sys.getenv("VSCR_LIB_PATHS")
if (nzchar(add_lib_paths)) {
add_lib_paths <- strsplit(add_lib_paths, "\n", fixed = TRUE)[[1L]]
.libPaths(c(.libPaths(), add_lib_paths))
}
loadNamespace("jsonlite")
ip <- installed.packages()
ord <- order(ip[, "Priority"])
ip <- ip[ord, ]
ret <- lapply(rownames(ip), function(row) {
libPath <- ip[row, "LibPath"]
pkg <- ip[row, "Package"]
filename <- file.path(libPath, pkg, "help", "aliases.rds")
info <- list(
package = pkg,
libPath = libPath,
aliasFile = filename,
aliases = NULL
)
if (file.exists(filename)) {
res <- tryCatch(
expr = as.list(readRDS(filename)),
error = conditionMessage
)
if (is.list(res)) {
info$aliases <- res
} else {
info$error <- res
}
}
info
})
names(ret) <- rownames(ip)
lim <- Sys.getenv("VSCR_LIM")
json <- jsonlite::toJSON(ret, auto_unbox = TRUE)
cat(lim, json, lim, sep = "\n", file = stdout())