Reputation: 2443
#!/usr/bin/Rscript
install.packages("Deriv")
install.packages("vegan")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/mirt/mirt_1.27.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
Above script is used to install packages.
How to make this script stop running (or quit) if anyone package is not installed successfully (warnings do not matter)?
Upvotes: 1
Views: 1415
Reputation: 70653
I would check installed packages after every install and use stop
to stop the script with a meaningful message. E.g.
install.packages("Deriv")
if (!"Deriv" %in% installed.packages()[, "Package"]) {
stop("Package Deriv not installed successfully.")
}
Upvotes: 2
Reputation: 2399
Is this what you are looking for?
if (
!all(
c('Deriv', 'vegan', 'mirt') %in% installed.packages()
)
) q()
Upvotes: 0