I'm trying to find a simple way to make install.packages()
throw an error if it fails (rather than just a warning).
What I've tried
Setting options(warn=2)
converts warnings into errors. Example:
options(warn=2)
warning()
# Error: (converted from warning)
I expected this would now error:
install.packages('thispackagedoesntexist')
# Warning in install.packages :
# package ‘thispackagedoesntexist’ is not available for this version of R
#
# A version of this package for your version of R might be available elsewhere,
# see the ideas at
# https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
yet it still just gives a warning (no error).
Question
How can install.packages() be made to error (rather than simply warn) on any sort of failure?
Note:
- There are a few nice ways of making install.packages() error instead of warning, but I'm scouting for something much more lightweight, preferably without installing other packages, which
options()
would achieve nicely (if I can get it working).