Automated Installation of R-Studio Using Shell Script

Automated Installation of R-Studio Using Shell Script

I have prepared the following shell script to make this installation fully automated.

#!/bin/bash
# ******************************************
# Program: R-Studio Installation Script
# Developer: Pratik Patil
# Date: 16-04-2015
# Last Updated: 16-04-2015
# ********************************************

if [ "`lsb_release -is`" == "Ubuntu" ] || [ "`lsb_release -is`" == "Debian" ]
then
sudo apt-get -y install r-base gdebi-core libapparmor1;
sudo wget http://download2.rstudio.org/rstudio-server-0.98.1103-amd64.deb;
sudo gdebi rstudio-server-0.98.1103-amd64.deb;

elif [ "`lsb_release -is`" == "CentOS" ] || [ "`lsb_release -is`" == "RedHat" ]
then
sudo yum -y install R openssl098e;
sudo wget http://download2.rstudio.org/rstudio-server-0.98.1103-x86_64.rpm;
sudo yum -y install --nogpgcheck rstudio-server-0.98.1103-x86_64.rpm;
else
echo "Unsupported Operating System";
fi

sudo rm -f rstudio-server-*;
sudo rstudio-server verify-installation;

How to Launch R-Studio in Ubuntu or Debian Systems?
Enter the following command on the terminal:

rstudio;

How to Launch R-Studio in CentOS or RedHat Systems?
Open the Following URL in browser:

http://localhost:8787

After that Login prompt will appear & then Login with the current system user credentials.

Loading R package inside R script

The solution is loading the package by require()

require(dplyr)

Installing R packages with bash script - responding to prompts

A different approach that works much better than what I originally posted:

In bash:

Create a specific library for installation (the same as the default R will want to create)

mkdir -p R/x86_64-pc-linux-gnu-library/3.3
Rscript --vanilla install_packages.R

In install_packages.R:

pkg_list <- # however you want to get this

for (pkg in pkg_list) {
install.packages(pkg, repos = "your_cran_mirror",
lib = "R/x86_64-pc-linux-gnu-library/3.3")
if (!require(pkg, character.only = T)) {
quit(save = "no", status = 1, runLast = FALSE)
}
}

Using this method, R will not prompt you and your script will run as intended.



Related Topics



Leave a reply



Submit