Frequently I am running R scripts in bash mode. My script is called 981_conduct_regression.R. In this script, I call required packages withif(!require(<package>)){  install.packages(<package>)  library(<package>)}Now when I call the script from bash mode (on Ubuntu 14.04), the script (shown below) fails to install the packages: Loading required package: gridExtraInstalling package into /home/michael/R/x86_64-pc-linux-gnu-library/3.1(as lib is unspecified)Error in contrib.url(repos, type) :   trying to use CRAN without setting a mirrorCalls: source ... eval -> eval -> install.packages -> grep -> contrib.urlIn addition: Warning message:In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :  there is no package called gridExtraExecution haltedWhat do I have to change for my idea to work?Edit: Here is the .sh file:#!/bin/bashRscript Code/981_conduct_regression.R
Install missing R packages when running in bash mode
r
You need to specify your CRAN mirror; interactively in R, runchooseCRANmirror()to pick an appropriate mirror, thenoptions(repos)to see the resulting URL. You can add this permanently to your configuration in ~/.Rprofile:local({r <- getOption(repos)   r[CRAN] <- <URL from above goes here>    options(repos=r)})