Getting R Set Up in Ubuntu

UPDATE: See these instructions for installing R in Ubuntu Intrepid. The instructions are mostly the same, except if you want to use JGR, you have to re-install JavaGD first.

R is a free, open source software package for performing statistical analyses. It is an alternative to commercial tools such as SPSS, SAS, and S. Here is a walkthrough on installing the latest version of R in Ubuntu Linux (Feisty), along with some graphical front-ends (JGR and R Commander and RKWard) and an R extension for OpenOffice. For instructions on installing these tools in Windows and Mac OS X, please see their respective websites.

In Ubuntu, this requires typing some commands in the Terminal (in the menu under Applications->Accessories). It seems like a lot of work, but most of the work you only have to do once, and it should be even easier in the future (when Ubuntu Gutsy is released). The version of R available in the Ubuntu Feisty repository is 2.4, however, the latest version of R at the moment is actually 2.5. If you are fine using 2.4, go to the System menu -> Administration -> Synaptic Package Manager and
search for “r-base” to install R that way. Otherwise, here are a few extra steps required to have access to the latest version (2.5):

Installing the Latest Version of R in Ubuntu

I am basing my instructions on this readme, which is unfortunately written out of order and incomplete. First in the terminal type these lines to add the security key to access the latest version of the R Ubuntu package:

gpg --keyserver subkeys.pgp.net --recv-key E2A11821
gpg -a --export E2A11821 | sudo apt-key add -

Then open up your apt-get sources list for editing:

sudo gedit /etc/apt/sources.list

Add this line to the bottom of the sources.list file:

deb http://rh-mirror.linux.iastate.edu/CRAN/bin/linux/ubuntu feisty/

You can replace “rh-mirror.linux.iastate.edu” with another mirror server of your choice. Save the file and go back to the Terminal.

Now type this in the terminal to update apt-get’s database before you install R:

sudo apt-get update

Install R with this command (the r-base-dev package is optional):

sudo apt-get install r-base r-base-dev

How to Start and Stop R

To start R, type “R” in the Terminal command line (no quotes, and uppercase):

R

To quit R, type this command inside R:

q()

And say yes to save the session if you wish.

Inside R, you can install either one of 2 GUI front ends to R, JGR and R Commander.

Installing JGR

To install JGR, first quit R. You need to make sure you have java installed and configured for use with R first.

To install Java 6 from Sun in Ubuntu, search for “java6″ in the Synaptic Package Manager and install the Java 6 packages. Then run this command in the terminal to configure Ubuntu to use Java 6 (this should not be required in Ubuntu Gutsy):

sudo update-alternatives --config java

Open /etc/jvm to set the default java runtime to use:

sudo gedit /etc/jvm

And add this line to the TOP of the file:

/usr/lib/jvm/java-6-sun

Then once java is properly configured, we can configure R to use Java. Type this command:

sudo R CMD javareconf

Now run R and type these lines in R to install JGR:

install.packages("JGR",dep=TRUE)

Now anytime you want to run JGR, type these commands in R:

library(JGR)
JGR()

Be sure when you exit R to save the session, so that you do not have to install JGR again.

Installing R Commander

To install R Commander, type this command inside R:

install.packages("Rcmdr", dependencies=TRUE)

And to run R Commander, type this in R:

library(Rcmdr)
//or run this if you quit R Commander in session already:
Commander()

Installing RKWard

To install RKWard, version 0.4.2 is available in the Ubuntu repositories, or else you can compile the newest version (0.4.7) manually yourself or else install the debian package on their site. See the site and the install notes contained in the download.

Updating Packages in R

Anytime you want to update the packages installed in R, type this command:

update.packages()

If you get errors compiling, you may need to install the build-essential package (using the synaptic package manager). If you get permission errors, you may need to quit R (type “q()”), the start R again with root permissions (“sudo R”). Then run update.packages() again and it should work.

Installing an R Extension for OpenOffice

There is also an R Extension for the OpenOffice spreadsheet tool (Calc) which may be worth trying. See the instructions on their site for installing. It requires installing the RServe package in R first, along with OpenOffice and Java. One missing item in the instructions is that the unopkg command line tool is located at /usr/lib/openoffice/program/unopkg

Learning more about R

It looks like a lot of hassle, but in the end you get a free, open source environment that is as powerful as SPSS/SAS and runs on any platform. There is a wealth of documentation out there on R, including numerous books on Amazon:

  • Numerous free 3rd party tutorials and courses on R
  • Introductory Statistics with R – book by Peter Dalgaard
  • Data Analysis and Graphics Using R: An Example-based Approach- book by John Maindonald
  • And there are at least 2 or 3 other books on Amazon about R as well.
About these ads
Posted in opensource, R, research
13 comments on “Getting R Set Up in Ubuntu
  1. isroi says:

    thanks a lot. It’s usefull information.

  2. isroi says:

    I follow your intruction above. But I had an error. There’s error massages:* Installing *source* package ‘JavaGD’ …checking for gcc… gcc -std=gnu99checking for C compiler default output file name… configure: error: C compiler cannot create executablesSee `config.log’ for more details.ERROR: configuration failed for package ‘JavaGD’** Removing ‘/usr/local/lib/R/site-library/JavaGD’error massages from R:Warning message:installation of package ‘JavaGD’ had non-zero exit status in: install.packages(“JavaGD”) How can I solve this problem?Thxisroi

  3. D Holton says:

    Someone else got that error and said the solution is to install libc-dev. Search for “libc” in synaptic package manager, or else run this on the command line:sudo apt-get install libc6-devSee the last post on this page:http://ubuntuforums.org/showthread.php?t=424921&page=2

  4. isroi says:

    I follow your suggestion. But I still fail to install some packages: rJava, JavaGD, and iplots. Here’s error massages:1: installation of package ‘rJava’ had non-zero exit status in: install.packages(“JGR”, dep = TRUE) 2: installation of package ‘JavaGD’ had non-zero exit status in: install.packages(“JGR”, dep = TRUE) 3: installation of package ‘iplots’ had non-zero exit status in: install.packages(“JGR”, dep = TRUE) I check with command : library(), These libraries not listed.Then, I download packages manually. But I can’t install packages from local directory. I try this command line:Install.Packages(“rJava”, lib=”~/R/library/”)andInstall.Packages(“rJava”, lib.loc=”~/R/library/”)I save download files in ~/R/library.How to install these packages from local directory?Thx.

  5. D Holton says:

    I’m sorry, I don’t know the answer to that. You will probably get an answer if you ask your question on the r-help mailing list:https://stat.ethz.ch/mailman/listinfo/r-helpGood luck with it.

  6. Anonymous says:

    thanks….

  7. Doug Holton says:

    Oct 3, 2007:When this URL shows a “gutsy” folder, these instructions will work for Ubuntu Gutsy (7.10) as well:http://rh-mirror.linux.iastate.edu/CRAN/bin/linux/ubuntu/I upgraded from feisty to gutsy, and my R installation still works fine, however it is not updated anymore.R 2.6 has now been released:https://stat.ethz.ch/pipermail/r-help/2007-October/142233.htmlHopefully 2.6 will be made available soon for Ubuntu either on the CRAN site or in the official Ubuntu Gutsy repository.

  8. Phil Rack says:

    Thanks for taking the time to document these steps. It really helped me out setting up my system. Greatly appreciated!

  9. Anonymous says:

    Hi, I am used to use R under windows, and there I had an application R…Not used to use R through console, is there way such that I can get R as an application-like?And another question: What is R-commander?

  10. Doug Holton says:

    I don’t think there is an R desktop application for Linux.But if you install JGR, you can just double click the launch script. What I did was drag it to my toolbar so I can click on it to launch it:/usr/local/lib/R/site-library/JGR/scripts/run

  11. Carolyn Candido says:

    how do you update R? The sudo apt-get command installs version 2.6.2 and I need version 2.7.

  12. Doug Holton says:

    In Intrepid now if you try to install JGR, you’ll get an error about JavaGD.So you have to install and compile JavaGD (have r-base-dev package installed). Start R and then run install.packages(“JavaGD”)It will download and compile it (hopefully). Then you can install.packages(“JGR”)See the comment at the bottom of this note:http://acercad.wordpress.com/2008/05/18/acerca-de-un-gui-hecho-en-java-para-r/

  13. Doug Holton says:

    I updated the instructions for Intrepid here:http://edtechdev.blogspot.com/2009/03/r-in-ubuntu-intrepid.htmlThey should work for Jaunty too whenever a Jaunty folder for R appears here:http://rh-mirror.linux.iastate.edu/CRAN/bin/linux/ubuntu/

Comments are closed.

Doug Holton

Doug Holton

Center for Teaching and Learning Excellence, Embry-Riddle Aeronautical University

Archives

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,096 other followers

Follow

Get every new post delivered to your Inbox.

Join 3,096 other followers

%d bloggers like this: