Frequently I am running R
scripts in bash mode. My script is called 981_conduct_regression.R
. In this script, I call required packages with
if(!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: gridExtra
Installing 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 mirror
Calls: source ... eval -> eval -> install.packages -> grep -> contrib.url
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘gridExtra’
Execution halted
What do I have to change for my idea to work?
Edit: Here is the .sh
file:
#!/bin/bash
Rscript Code/981_conduct_regression.R
981_conduct_regression.R
? It is better if you keep things self-contained. Less confusing. Give a minimal named example script in your question, run it, then give the output. – Faheem Mitha Feb 07 '15 at 12:22