install.packages()
returns a warning if a package cannot be installed (for instance, if it is unavailable); for example:
install.packages("notapackage")
(EDIT: I'd like to throw an error regardless of the reason the package cannot be installed, not just this example case of a missing package).
I am running the install.packages
command in a script, and I would like it to trigger a proper error and exit execution. I don't see an obvious option inside install.packages
for handling this behavior. Any suggestions?
available.packages()
first?install.package2 <- function(...){ifelse(any(grepl("Warning", capture.output(install.packages(...)))), 1, 0)}
andcake.installer("cake"); cake.installer("lmtest")
withCallingHandlers()
...