Skip to content

Instantly share code, notes, and snippets.

@mllg
Created November 28, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mllg/b9c75ded211df7df58942c5d647b9c43 to your computer and use it in GitHub Desktop.
Save mllg/b9c75ded211df7df58942c5d647b9c43 to your computer and use it in GitHub Desktop.
Rebuild R packages after system libraries have been upgraded
#!/usr/bin/env Rscript
libs = c("libopenblas", "libicu")
packages = character()
patterns = sprintf("^%s.* => not found$", libs)
for (lib in .libPaths()) {
files = list.files(path = lib, pattern = "\\.so(\\.[0-9]+)*$", recursive = TRUE,
ignore.case = TRUE, full.names = TRUE, no.. = TRUE)
for (file in files) {
lines = suppressWarnings(trimws(system2("ldd", file, stdout = TRUE, stderr = TRUE)))
for (pattern in patterns) {
if (any(grepl(pattern, lines))) {
packages = c(packages, basename(dirname(dirname(file))))
}
}
}
}
if (length(packages)) {
install.packages(unique(packages))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment