Installation script to add packages from Cran R

If you use the free software cran R to do data analysis and you are also that kind of person that likes to have the last version then you may be interested in this.  Many times i compile the last version of Cran R from scratch but have the problem that many packages are not automatically available for that version yet, the only solution is to download and compile them manually which is a lot of effort given all the dependencies.

I know that this is not a great solution, but it saved me a lot of time, it can be improved.

First you will need an index from the packages, you can create it so:

wget "https://cran.r-project.org/src/contrib/" -O pkgs.txt

And then you will have to run these lines a few times until all the dependencies are installed:

INSTALAR="ggplot2_2.2.1.tar.gz";
R CMD INSTALL ${INSTALAR} 2> /tmp/err
while [[ `cat /tmp/err | grep ERRO | wc -l` -ne 0 ]]; do
 i=`cat /tmp/err | grep "ERROR" | sed 's/.*dependenc[a-z]\{1,4\} //g' | sed 's/’ [are |is ].*//g' | sed 's/[,’‘]//g' | cut -f1 -d" "`;
 echo "Installing dependency $i";
 PP=`cat pkgs.txt | grep "^${i}_"`;
 if [ ! -e $PP ]; then wget "https://cran.r-project.org/src/contrib/$PP" -O $PP; fi;
 echo "Installing ${PP}";
 R CMD INSTALL ${PP} 2> /tmp/err;
done

If you want to install the “ggplot2” package, just put the package name in the variable “INSTALAR” and run the script.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s