Last active
December 13, 2015 23:21
-
-
Save HenrikBengtsson/7881a291cdd61708ba51 to your computer and use it in GitHub Desktop.
Identifying R packages that fail to load and try to re-install them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Identify installed packages that fail to load | |
rscript <- function(...) { | |
system2(file.path(R.home("bin"), "Rscript"), ...) | |
} | |
works <- function(pkg) { | |
## Need to call in separate R session to not use up all DLLs | |
rcmd <- sprintf("cat(isTRUE(requireNamespace('%s')))", pkg) | |
as.logical(rscript(args=c("-e", dQuote(rcmd)), stdout=TRUE)) | |
} | |
pkgs <- installed.packages() | |
pkgs <- pkgs[(pkgs[,"NeedsCompilation"] == "yes"),"Package"] | |
pkgs <- sort(unique(pkgs)) | |
ok <- sapply(pkgs, FUN=works) | |
bad <- pkgs[!ok] | |
## Try to reinstall | |
install.packages(bad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment