Monday, November 7, 2011

Setting up R on Red Hat Linux

Thought of giving R programing a shot to create graph, so I downloaded the source code and compiled it on my Red Hat Linux server.


[root@isvx7 ~]# uname -a
Linux isvx7.storage.tucson.ibm.com 2.6.18-274.3.1.el5 #1 SMP Fri Aug 26 18:49:02 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux


So as user root I created a directory called r_prog. Under directory I created a directory called
source. I then cd'ed on to the source directory and downloaded the source code for R.


[root@isvx7 source]# wget http://cran.r-project.org/src/base/R-2/R-2.14.0.tar.gz

I next untared to .gz file


[root@isvx7 source]# tar -xvf R-2.14.0.tar.gz

Next I cd onto the directory R-2.14.0 and ran "configure"


[root@isvx7 source]# ./configure

.....
.....
....

R is now configured for x86_64-unknown-linux-gnu

  Source directory:          .
  Installation directory:    /usr/local

  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  C++ compiler:              g++  -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:

  Interfaces supported:      X11
  External libraries:        readline
  Additional capabilities:   PNG, JPEG, TIFF, NLS, cairo
  Options enabled:           shared BLAS, R profiling, Java

  Recommended packages:      yes

configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of all the help pages
[root@isvx7 R-2.14.0]#

I then ran the "make" and "make check" command as shown below.

[root@isvx7 R-2.14.0]# make
......
......
......


[root@isvx7 R-2.14.0]# make check
make[1]: Entering directory `/root/r_prog/source/R-2.14.0/tests'
make[2]: Entering directory `/root/r_prog/source/R-2.14.0/tests'
make[3]: Entering directory `/root/r_prog/source/R-2.14.0/tests/Examples'
Testing examples for package âbaseâ
  comparing âbase-Ex.Routâ to âbase-Ex.Rout.prevâ ...
5654c5654
< 54
---
> 14
Testing examples for package âtoolsâ
  comparing âtools-Ex.Routâ to âtools-Ex.Rout.saveâ ... OK
Testing examples for package âutilsâ
  comparing âutils-Ex.Routâ to âutils-Ex.Rout.prevâ ... OK
Testing examples for package âgrDevicesâ
  comparing âgrDevices-Ex.Routâ to âgrDevices-Ex.Rout.saveâ ... OK
Testing examples for package âgraphicsâ
  comparing âgraphics-Ex.Routâ to âgraphics-Ex.Rout.saveâ ... OK
Testing examples for package âstatsâ
  comparing âstats-Ex.Routâ to âstats-Ex.Rout.saveâ ... OK
Testing examples for package âdatasetsâ
  comparing âdatasets-Ex.Routâ to âdatasets-Ex.Rout.saveâ ... OK
Testing examples for package âmethodsâ
  comparing âmethods-Ex.Routâ to âmethods-Ex.Rout.prevâ ... OK
..............................................................
..............................................................
..............................................................
..............................................................
running code in 'reg-plot-latin1.R' ... OK
  comparing 'reg-plot-latin1.ps' to './reg-plot-latin1.ps.save' ... OK
make[3]: Leaving directory `/root/r_prog/source/R-2.14.0/tests'
make[2]: Leaving directory `/root/r_prog/source/R-2.14.0/tests'
make[2]: Entering directory `/root/r_prog/source/R-2.14.0/tests'
running tests of Internet and socket functions
  expect some differences
make[3]: Entering directory `/root/r_prog/source/R-2.14.0/tests'
running code in 'internet.R' ... OK
  comparing 'internet.Rout' to './internet.Rout.save' ...17c17
< [1] 3373
---
> [1] 3383
 OK
make[3]: Leaving directory `/root/r_prog/source/R-2.14.0/tests'
make[2]: Leaving directory `/root/r_prog/source/R-2.14.0/tests'
make[1]: Leaving directory `/root/r_prog/source/R-2.14.0/tests'
[root@isvx7 R-2.14.0]#

If you get a whole bunch of OK's then R is ready to go.


[root@isvx7 R-2.14.0]# ls
bin            COPYING  libtool      Makefrag.cc     ONEWS         tests
ChangeLog      doc      m4           Makefrag.cc_lo  OONEWS        tools
config.log     etc      Makeconf     Makefrag.cxx    po            VERSION
config.site    include  Makeconf.in  Makefrag.m      README
config.status  INSTALL  Makefile     modules         share
configure      lib      Makefile.fw  NEWS            src
configure.ac   library  Makefile.in  NEWS.pdf        SVN-REVISION
[root@isvx7 R-2.14.0]#

Now go into the bin directory and run R.


[root@isvx7 R-2.14.0]# cd bin
[root@isvx7 bin]# ls
BATCH    config   javareconf     pager   Rdconv      Rprof    Stangle
build    exec     libtool        R       Rdiff       Rscript  Sweave
check    f77_f2c  LINK           Rcmd    REMOVE      rtags
COMPILE  INSTALL  mkinstalldirs  Rd2dvi  Rplots.pdf  SHLIB
[root@isvx7 bin]# ./R

R version 2.14.0 (2011-10-31)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

>

At this point I tried the example provided in for the following link:
http://www.harding.edu/fmccown/r/


>
> cars <- c(1, 3, 6, 4, 9)
> plot(cars)
> q()
Save workspace image? [y/n/c]: y
[root@isvx7 bin]#
This created a graph called Rplots.pdf under the current directory.