# To install dependencies for compiling R
sudo apt-get build-dep r-base # this will install many open-jdk things instead use below things
sudo apt-get install r-base r-recommended r-base-dev


# To install documentation in HTML format for packages in core R and manuals in PDF format 
sudo apt-get install r-base-html r-doc-pdf

# Downloading via http
# [It is advised to download latest version from - http://cran.r-project.org/]
# or from here http://ftp.iitm.ac.in/cran/
wget https://cran.rstudio.com/src/base/R-3/R-3.2.2.tar.gz
# You can download latest R version from CRAN
# Go to http://cran.r-project.org/
# or Go & choose what u want:- http://cran.r-project.org/src/base/

# Untar
tar -xzf R-3.2.2.tar.gz
cd R-3.2.2.tar.gz

# need to build shared library (--enable-R-shlib)
sudo ./configure  --enable-R-shlib      # --prefix=...
sudo make
sudo make install

# R will be done

# Re-configuring java for R
 R CMD javareconf

# some dependencies for R packages-

# RCurl:- sudo apt-get install libcurl4-gnutls-dev  libcurl4-openssl-dev
# XML:- sudo apt-get install libxml2-dev