Sunday, April 1, 2012

How to install R, JGR and Deducer in Ubuntu

A step-by-step guide about how to install the free statistical software GNU R, JGR and Deducer in Ubuntu (>= 10.04.4) and others Ubuntu derivative distributions. (see Romanian version / vezi versiunea în română)



The combination of GNU R, JGR and Deducer is a powerful free alternative to all proprietary / commercially distributed statistical programs like SPSS. Together, they provide a wide variety of statistical and graphical techniques, combined with intuitive graphical menus and dialogues that guide the user efficiently through the data manipulation and analysis process.

To install R, JGR and Deducer in Ubuntu, follow the steps described below, or use the installation script that I developed for this purpose.

1. Install the most recent R version

To obtain the latest R packages, add in your /etc/apt/sources.list file a repository URL for the Ubuntu archives on CRAN (choose a CRAN Mirror that is geographically close to you). Run in terminal:
sudo editor /etc/apt/sources.list

and add to the end of the file (replacing codename with your release code name; for example, mine release is called precise, from Precise Pangolin):
deb http://cran.r-project.org/bin/linux/ubuntu codename/

Add the secure key for the Ubuntu archives on CRAN (run in terminal):
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -

Install R (run from terminal):
sudo apt-get update
sudo apt-get install r-base-dev

To avoid some later errors:
sudo apt-get install libx11-dev libglu1-mesa-dev libxml2-dev

If your network is behind a proxy/firewall, you can't directly install and update R packages. To solve the problem, you need to add to (one of) /etc/R/Rprofile.site or ~/.Rprofile files the following lines (substituting your own username, password, proxy server and port settings):
local({
Sys.setenv(http_proxy="http://username:password@tcdproxy.tcd.ie:8080")
})

Note that the username:password@ part is needed only if the proxy requires authentication.

For me the added lines was:
local({
Sys.setenv(http_proxy="http://192.168.1.254:3128/")
})

Putting http_proxy=http://192.168.1.254:3128/ in ~/.Renviron will work too.

2. Install Java Development Kit and enable Java support in R

For this step follow instructions from the post How to install Java / OpenJDK in Ubuntu. Do not forget after that to enable Java support in R (run in terminal):
sudo R CMD javareconf

3. Install JGR, Deducer, DeducerExtras and DeducerRichOutput packages (for other extension packages for Deducer look in the online manual)

Run in terminal:
sudo R --no-save

Run in R environment:
update.packages(ask=FALSE, repos = 'http://cran.r-project.org')
install.packages(c('JGR', 'Deducer', 'DeducerExtras'), repos = 'http://cran.r-project.org')
install.packages('DeducerRichOutput', repos = 'http://R-Forge.R-Project.org')
install.packages('XLConnect', repos = 'http://cran.r-project.org') ## for importing Excel files

4. Add a menu entry for JGR

Run in R environment (started in previous step):
library(JGR)
JGR()
q()

This will create a launcher for JGR.
Close (if) opened JGR window.

Download an icon image for JGR (run in terminal):
sudo wget http://goo.gl/U5hk9 -O /usr/share/icons/jgr-48x48.jpg

Create a .desktop file for the JGR menu entry. For this run in terminal:
sudo editor /usr/share/applications/jgr.desktop

and copy/paste the bellow content:
[Desktop Entry]
Type=Application
Terminal=false
Name=JGR - Java Gui for R
Exec=/usr/local/lib/R/site-library/JGR/scripts/run
Icon=/usr/share/icons/jgr-48x48.jpg
Comment=Java Gui for R
Categories=Science;Education;

Save created file with Ctrl+X.

5. Set JGR to auto-load Deducer, DeducerExtras and DeducerRichOutput packages

Start JGR from your account (Applications > Science > JGR - Java GUI for R), open Packages & Data > Package Manager menu, select load and default next to Deducer, DeducerExtras and DeducerRichOutput, click on Close button.

See Romanian version / vezi versiunea în română: Instalarea limbajului R în Ubuntu

Risk disclaimer
Attention! Use the content of this blog at your own risk! Please, make sure that you understand what you are doing! I will not be held responsible for any harm or damage caused by the use of this blog content under any circumstances!