Skip to content

Commit

Permalink
also capture library paths + installed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Feb 21, 2020
1 parent 170a82a commit bfcdecb
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/cpp/r/R/Diagnostics.R
Expand Up @@ -83,6 +83,19 @@ dumpfile <- function(path) {

}

envvars <- function() {

# log environment variables, redacting any banned words (e.g. those that might
# expose API tokens or other secrets). match it on the list of environment
# variable names with _ converted to a space (so that e.g. GITHUB_PAT becomes
# GITHUB PAT and matches the banned word PAT)
vars <- Sys.getenv()
keys <- gsub("_", " ", names(vars), fixed = TRUE)
matches <- grepl(redact_regex(), keys, ignore.case = TRUE)
vars[matches] <- "*** redacted ***"
as.list(vars)
}

# Main script ----

capture.output(file = diagnosticsFile, {
Expand Down Expand Up @@ -120,25 +133,24 @@ sensitive information before submitting your diagnostics report.
dump(.Platform)
newlines()

header("Environment Variables")
dump(envvars())
newlines()

header("R Version")
dump(R.Version())
newlines()

# log environment variables, redacting any banned words (e.g. those that might
# expose API tokens or other secrets). match it on the list of environment
# variable names with _ converted to a space (so that e.g. GITHUB_PAT becomes
# GITHUB PAT and matches the banned word PAT)
envVars <- Sys.getenv()
matches <- grepl(
redact_regex(),
gsub("_", " ", names(envVars), fixed = TRUE),
ignore.case = TRUE
)
header("R Home")
dump(R.home())
newlines()

envVars[matches] <- "*** redacted ***"
header("R Search Path")
dump(search())
newlines()

header("Environment Variables")
dump(as.list(envVars))
header("R Library Paths")
dump(.libPaths())
newlines()

header("Loaded Packages")
Expand All @@ -148,13 +160,19 @@ sensitive information before submitting your diagnostics report.
dump(sort(paths))
newlines()

header("R Home")
dump(R.home())
newlines()
local({

op <- options()
on.exit(options(op), add = TRUE)
options(width = 1000, max.print = 50000)

header("Installed Packages")
ip <- as.data.frame(installed.packages(noCache = TRUE), stringsAsFactors = FALSE)
rownames(ip) <- NULL
print(ip[c("Package", "LibPath", "Version")])
newlines()

header("R Search Path")
dump(search())
newlines()
})

# dump .Rprofiles
r_base_profile <- file.path(R.home(), "library/base/R/Rprofile")
Expand Down

0 comments on commit bfcdecb

Please sign in to comment.