# Using Different Versions of R

Installing GenePattern (version 3.1 and later) installs R 2.5.

• On Windows, R 2.5 is installed within the GenePattern directory and should not impact other installations of R that may be on your computer.
• On Mac it is installed in the standard location, /Library/Frameworks/R.framework/Versions/2.5.
• Linux users must install R on their own and point the GenePattern installation to the location of R.

The GenePattern modules available in the Broad Institute repository (Modules & Pipelines>Install from repository) all work with R 2.5. However, some GenePattern modules require different versions of R; for example, ExpressionFileCreator v.10 requires R 2.8. Unfortunately, R is not backward compatible. If you simply install and run the latest version of R, modules may fail or (worse) may produce invalid results even though they do not fail.

## Defining R in GenePattern

In GenePattern, each module definition includes a command line that runs the analysis program. For an R module, the R version is defined by a command line substitution parameter. For example, the <R> parameter is substituted with the full path to the R 2.0.1 executable. The <R2.5> parameter is substituted with the full path to the R 2.5 executable. Similar parameters are used for other versions of R.

GenePattern version 3.1 and later installs R 2.5 and sets the <R2.5> parameter. If you upgraded from GenePattern 3.0, your GenePattern installation also includes R 2.0.1 and sets the <R> parameter.

To add a different version of R to your GenePattern installation (for example R 2.8 on Mac OS X, for ExpressionFileCreator v. 10):

1. Install the required version of R, if necessary. This is covered in detail on the R Project home page.
1. Go to http://www.r-project.org/ and select a CRAN mirror.
2. Locate either the source code or the binary for the desired version of R. For a binary installation, look for the subdirectory link labeled 'old', which is towards the bottom of the page.
2. After you install the correct version of R, in whatever manner makes sense to you, you need to configure GenePattern to use that version of R. This is as simple as adding two new substitution parameters to the server settings.
1. Click Administration>Server Settings and go to the Custom page.
2. Add a setting for R*_HOME and another for R*, replacing the '*' with an actual version number.
• For R 2.8 on Mac OS X the parameters are:
 R2.8_HOME=/Library/Frameworks/R.framework/Versions/2.8/Resources R2.8= -DR_suppress= -DR_HOME= -Dr_flags= -cp RunR
• For other platforms, set R2.8_HOME equal to the full path to the installation directory. It must be a directory which contains a 'bin' folder, which contains the 'R' executable.

## Using Multiple Versions of R on Mac OS X [SECTION IN PROGRESS]

While it is possible to run multiple versions of R on a Mac, doing so requires more care and effort than on Windows or Linux.  In particular, you need to pay careful attention to choosing the R versions that are required and use caution during installation.  The order of operations is important and performing steps out of sequence can adversely affect versions already installed on the machine or require backtracking in the process.  You can find the CRAN installers for different versions of R here but please read the following before proceeding.  The GenePattern team has not fully evaluated all of the possible issues and combinations involved in supporting multiple R installations on a Mac.  What follows is our best understanding at present.

When you install R from CRAN (for example, R 2.8), that version of R becomes the current version of R on your system.  This is true even if you had previously installed a newer version of R such as R 2.15. Executing R from a Terminal command line or the R GUI will run the last installed version.

By default, the CRAN installer will also update other installed versions, possibly resulting in these being removed or otherwise adversely affected. This is spelled out in a README displayed within the installer (the second step of the installers thus far tested).  It also provides instructions to avoid these effects.  If you want to run multiple versions of R with GenePattern on the Macintosh, these instructions apply to you.

Tiger builds come as DMG files while Leopard builds come as PKG files.  Before installing an additional version, you will need to do one of the following from the command line (probably as sudo or administrator), depending on the version that you are installing:
• For R 2.5 (and possibly earlier) to 2.10 (Tiger builds):  "remove R-Framework.pkg from /Library/Receipts before proceeding."
• For R 2.10 to R 2.15 (Leopard builds):  "pkgutil --forget org.r-project.R.Leopard.fw.pkg"
• R 2.10 was transitional, so the correct instructions depend on whether it is installed from the DMG (Tiger) or the PKG (Leopard) file.
There is some inconsistency in that installing a Leopard build does not appear to upgrade/affect an existing installed Tiger build other than taking over the position as the current version of R.  The reverse seems to be true as well: installing a Tiger build does not seem to affect a Leopard build already in place.  Regardless, we recommend following the official R developer README instructions before each installation of a new version.

Information from this posting on the R-SIG-Mac mailing list indicates that these README instructions only work for earlier versions of R (like installing 2.15 after 2.12) and that doing it the other way (installing 2.15 first, then 2.12) will adversely affect existing installed versions.  The GenePattern team has not fully tested the various combinations but have seen problems that occur based on installation order.  We recommend first carefully choosing the versions you need and then installing them in ascending order.

If you are running R from outside of GenePattern and need to use a different version, you can use the RSwitch program to change which is current.  For example, after you install R 2.8 you can use RSwitch to switch back to R 2.15.  There are other options as well. This is documented in the R for Mac OS X FAQ.  Note, however, that the README instructions for keeping multiple installations of R (using "remove" or "pkgutil") are not sufficient if you intend to use RSwitch.  The GenePattern team does not have specific recommendations on this kind of setup at this time but further details are available from this post on the R-SIG-Mac mailing list.

The use of RSwitch is not effective for use from GenePattern due to the need to run multiple R versions at the same time. As a workaround, you must manually edit the installed executable shell scripts. Replace all hard coded paths to /Library/Frameworks/R.framework/Resources with the actual path to the correct installed version of R as described by this posting from the R-SIG-Mac mailing list. The file r_mac_osx_binary_patches.tar contains patches for modifying some versions of R.  For other versions, here are the important scripts to modify (not all present in every version):
• /Library/Frameworks/R.framework/Versions/<your R version>/Resources/bin/R
• /Library/Frameworks/R.framework/Versions/<your R version>/Resources/bin/R32
• /Library/Frameworks/R.framework/Versions/<your R version>/Resources/bin/R64
• /Library/Frameworks/R.framework/Versions/<your R version>/Resources/etc/i386/Makeconf
• /Library/Frameworks/R.framework/Versions/<your R version>/Resources/etc/x86_64/Makeconf
Be aware that, according to that R-SIG-Mac posting, there may be some issues with this set-up.  If you use R outside of GenePattern, we recommend that you use RSwitch to set your favored version as Current.

GenePattern modules are configured so that they use a particular version of R (e.g., R 2.8), regardless of the value of the current version.  However, we have seen cases of modules switching from their configured version of R to a different version after an R installation or use of RSwitch.  We are actively working on the issue but you should be aware of this for the time being.

The upcoming R 3.0 is the first version that requires OS X Snow Leopard, but it comes as a PKG file and also gives the same instructions as the Leopard builds.  That installer seems to behave the same as the Leopard installers described above.  The GenePattern team has not tested any GenePattern components on R 3.0 and do not recommend it for use with GenePattern at this time.

## Adding R Version 2.0.1 to GenePattern

There are some GenePattern modules which rely on R version 2.0.1:

• CoxRegression
• LogisticRegression
• MultiplotPreprocess
• NearestTemplatePrediction

To use these modules on your server you need to add R version 2.0.1.