Computing

Latest Version of R on Ubuntu Linux

Full instructions can be found at http://cran.r-project.org/bin/linux/ubuntu/README

Basic R Package Installation

Using an Ubuntu repository

Numerous R packages have been compiled into binary Ubuntu packages that can be installed from the official Ubuntu repository. You can see which packages are available for your version of Ubuntu with the following command:

 apt-cache search r-cran`</code>`
However, because packages in the Ubuntu repository become outdated over time, it is often preferable to install and manage R packages using R itself (see below) rather than the Ubuntu package manager. A major exception is the suite of R packages contained in *r-recommended*, which will pull from the CRAN-hosted Ubuntu repository if you installed R as described above; this repository is generally kept up-to-date as new versions of the *r-recommended* packages arise.

####  Installing directly from CRAN
For the vast majority of packages, installation and maintenance is easily accomplished from within R itself. Note, however, that R must be started with root privileges (i.e. use 'sudo R') in order to make system-wide changes. (If you do not have root privileges, you will still have an opportunity to install the package in your local user directory.)
`<code rsplus>`
 # Install a package
 > install.packages("pkgname")
 # Upgrade any outdated packages
 > update.packages()
 # Rebuild packages after upgrading to a new minor version of R (e.g. 2.4 -> 2.5)
 > update.packages(checkBuilt=TRUE,ask=FALSE)

Troubleshooting

In Linux, the install.packages() function downloads package source code and then compiles the package locally. Although this is a straightforward process, it does introduce some additional opportunities for something to go wrong. Common causes of problems are:

Installation directory is not writable

Did you remember to run R as root (‘‘sudo R’’)?

Package requires newer version of R

Be sure that R is up-to-date.

Package depends on other uninstalled R packages

Recent versions of R will generally fetch necessary packages automatically. However, sometimes dependencies will need to be installed manually. Installation can also fail if required packages are not up-to-date.

Missing compiler tools

Typically just requires an alternative compiler to be installed; inspect the error message for details.

Missing libraries or headers

Typically requires some external package(s) to be installed; inspect the error message for details about what is missing. See next section for some packages that build atop external libraries or applications.

Non-standard path

May arise if a necessary external file or directory exists, but resides in a non-standard location. The correct path can be specified with a configuration option, though it may be more convenient to create a symlink.

X11/X11 Forwarding

Some packages (iplots, JGR) may fail to upgrade without X11 present and X11 forwarding enabled

Installation tips for R packages with external dependencies

Your mileage may vary with these tips depending on your version of Ubuntu, your version of R, your system configuration settings, and previously installed applications. It is almost always worth trying to install a package using the basic method described above, and then proceeding to troubleshoot if this fails.

R2WinBUGS: Running WinBUGS and OpenBUGS from R/S-PLUS

WinBUGS is a Windows application, but it can be run on an Ubuntu system using the Wine compatibility layer. First install Wine, if you don’t already have it:

 sudo apt-get install wine

Note: WinBUGS14 has been observed to run successfully using the Wine packages available in the official Ubuntu repositories (tested on Dapper, Edgy, and Feisty). However, newer versions of Wine obtained directly from the WineHQ repos may not work. For example, as of 28-Aug-2007, WinBUGS14 does not run properly using recently released Wine version 0.9.44 on Ubuntu Feisty.

After installing Wine, download the WinBUGS installer and install with Wine:

 wine WinBUGS14.exe`</code>`

Next, assuming you've accepted the default installation directories, start up WinBUGS:
`<code>`
 wine ~/.wine/drive_c/Program\ Files/WinBUGS14/WinBUGS14.exe

(Tip: you may want to alias this command if you are likely to use WinBUGS as a standalone application!) Before starting any analyses, follow the straightforward directions here for installing the most recent patch and obtaining/decoding the (free) license key. After doing this, WinBUGS should be fully functional as a standalone application for MCMC simulation.

Finally, to enable WinBUGS execution from R, install the R2WinBUGS package within R as described above. See Andrew Gelman’s site for sample code; in order to make this work using Wine, call the bugs() function with several extra Wine configuration arguments:

 > bugs(//`<assorted actual model arguments>`//, useWINE=TRUE,
       bugs.directory = path.expand("~/.wine/drive_c/Program Files/WinBUGS14"),
       newWINE=TRUE, WINE="/usr/bin/wine", WINEPATH="/usr/bin/winepath")`</code>`

####  [[http://cran.r-project.org/src/contrib/Descriptions/rgdal.html|rgdal: Bindings for the Geospatial Data Abstraction Library]]
First install GDAL and PROJ.4 libraries:
`<code>`
 sudo apt-get install libgdal1-dev proj`</code>`  *Note: Although the official Ubuntu repositories provide both gdal and proj, more up-to-date versions of these packages can be obtained from the [[http:*trac.osgeo.org/ubuntugis/wiki/UbuntuGISRepository|UbuntuGIS]] repository. The *stable* incarnation of this repository is updated every 6 months, and the *unstable* repository is updated even more frequently. To enable the stable repository, add the following lines to your /etc/apt/sources.list file (substituting your Ubuntu version for *karmic* if appropriate)://

`<code>`
 deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu karmic main
 deb-src http://ppa.launchpad.net/ubuntugis/ppa/ubuntu karmic main`</code>`

Then authenticate the repository and update your package list before installing gdal and proj as described above: <code> sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 314DF160 sudo apt-get update</code>

After installing these packages, install the **rgdal** package from within R as described above. Note **rgdal** depends on the R package **sp**.

####  [[http://cran.r-project.org/src/contrib/Descriptions/rgl.html|rgl: 3D visualization device (OpenGL)]]
First install headers for X11 and Mesa (an implementation of OpenGL):
`<code>`
 sudo apt-get install xorg-dev mesa-common-dev libglu1-mesa-dev`</code>`

Then install the **rgl** package from within R as described above.

####  [[http://cran.r-project.org/src/contrib/Descriptions/RGtk2.html|RGtk2: R bindings for Gtk 2.8.0 and above]]
First install headers for GTK (the GIMP Toolkit):
`<code>`
 sudo apt-get install libgtk2.0-dev`</code>`

Then install the **RGtk2** package from within R as described above.