Last modified on 23 November 2013, at 19:39

R Programming/Settings

This page show how to install R, customize it and choose a working environment. Once you have installed R, you may want to choose a working environment. This can be a simple text editor (such as Emacs, Vim or Gedit), an integrated development interface (IDE) or graphical user interface (GUI). RStudio is now a popular option.

InstallationEdit

LinuxEdit

Installing R on Debian-based GNU/Linux distributions (e.g. Ubuntu or Debian itself) is as simple as to type in sudo aptitude install r-base or sudo apt-get install r-base (don't forget that this is have to be done as root), or installing the package r-base using your favourite package manager, for example Synaptic.

There is also a bunch of packages extending R to different purposes. Their names begin with r-. Take a closer look at the package r-recommended. It is a metapackage that depends on a set of packages that are recommended by the upstream R core team as part of a complete R distribution. It is possible to install R by installing just this package, as it depends on r-base.

Installation with apt-get (Debian, Ubuntu and all linux distributions based on Debian)

sudo apt-get install r-base
sudo apt-get install r-recommended

Installation with aptitude (Debian, Ubuntu and all linux distributions based on Debian)

sudo aptitude install r-base
sudo aptitude install r-recommended

Mac OSEdit

Installation : Visit the R project website (http://r-project.org/), select the "CRAN" page and choose mirror. Download the disk image (dmg file) and install R.

The default graphical user interface for Mac is much better than the one for Windows. It includes

  • a dataframe manager,
  • a history of all commands,
  • a program editor which supports syntax highlighting.

WindowsEdit

(Section source [1])

DownloadEdit

To install R under Windows operating system you have to download the binaries from the web. First go to r-project.org and click CRAN under download section on the left panel and select a mirror site, from where you could download the required content. The best idea is pick a mirror closest to your actual geographical location, but other ones should work as well. The click Windows and in subdirectories base. The windows binary is the exe file, in form R-x.x.x-win32.exe, where x denotes the actual version of the program. Regardless of the version the setup has the same steps.

SetupEdit

As usual in Windows, if you just keep clicking the Next button, you will install the program without any problems. However, there are few things that you can alter.

  1. On the welcome screen click Next.
  2. Read or just notice the GNU license, and click Next.
  3. Select the location, where R should be installed. In case you don't prefer a particular location on your hard disc, the default choice will be OK for you.
  4. During the next step you can specify which parts of R you want to install. Choices are: User installation, Minimal user installation, Full installation and Custom installation. Notice the required space under the selection panel (varies between 20 and 66 MB). In case you are a beginner in R, choose the default User installation.
  5. In this step you can choose between 2 ways. If you accept defaults, you skip the 3 "extra" steps during installation (see lower).
  6. You can specify the Start menu folder.
  7. In the next step you can choose, between shortcut possibilities (desktop icon and/or quick launch icon) and specify registry entries.


With these steps you can customize the R graphical user interface.

  • You can choose if you want an R graphic user interface covering the whole screen (MDI) or a smaller window (SDI).
  • You can select the style, how the Help screen is displayed in R. You will use help a lot, so this may be an important decision. It is up to you, which style you prefer. Please note, that the content of help file will be the same regardless of your choice. Here you specify just the appearance of that particular window.
  • In the next step you can specify, whether you want to use internet2.dll. If you are a beginner, pick the Standard option here.

UpdateEdit

Updating R on Windows requires several steps:

  1. Downloading/installing the latest version of R
  2. Copying your packages from the library folder to the one in the new R installation

Both of these steps can easily be done using the installr package, by running the following command (which would both install the package, and update R) [2]:

# installing/loading the package:
if(!require(installr)) { 
install.packages("installr"); require(installr)} #load / install+load installr
updateR() # updates R

There is also the possibility of using a "global" package library, see here for more details.

Portable R for WindowsEdit

You have a portable version if you want to install R on your USB stick[3]. This is useful if you don't have admin rights on a computer. The basic installation requires something like 115 mb but you may need more if you want to install add-on packages.

Working environmentEdit

Once you have installed R, you need to choose a working environment. In this section, we review all possible working environment. This include a basic terminal as well as integrated development environment (therefore IDE), text editors or graphical user interface (therefore GUI).

  • A graphical user interface provides some menu which makes it possible to run R without writing code. This is a good solution for beginners.
  • A text editor makes it easy to write code.
  • An integrated development environment provides a text editor and a compiler which makes it easy to write R scripts, to run them and to correct them.

Note that there are some task specific GUIs. For instance speedR provides a GUI to import data into R.

TerminalEdit

R in a Terminal window on Linux.

For Linux and Mac OS users it is possible to use R from the terminal.

$ R
> q("no") # to leave R and return to the terminal

R GuiEdit

For Mac OS and Windows users, there is a graphical user interface. In Mac OS, the GUI includes a package manager, a program editor with syntax highlighting and a data browser. In Windows, the GUI is not better than a Terminal.


Graphical User InterfaceEdit

This section includes material for beginners (eg people who are not familiar with computing).

Poor Man's GUI (pmg)Edit

A simple GUI for learning R. It is recommanded for beginners.

> install.packages("pmg", dependencies=TRUE)
# Windows users may also run the following scripts to install required libraries
> source("http://www.math.csi.cuny.edu/pmg/installpmg.R")


> library(pmg)

Jaguar : Java GUI for REdit

  • Jaguar : Java GUI for R[4] is available for Linux, Mac and Windows (screenshots).
  • It is good for beginners.

R commanderEdit

  • Rcommander[5] developed by John Fox provides a menu in the standard Graphical User Interface (screenshots).
  • It works on Linux, Mac and Windows.
  • It is a good interface for beginners and for people who are not used to script editing.
> install.packages("Rcmdr") # installation
> library("Rcmdr") # usage
  • Ubuntu users can also install R Commander from the software center.


Integrated development environmentEdit

RStudioEdit

RStudio on Ubuntu 12.10.

RStudio is an integrated development interface for R[6].

  • It works on Mac, Windows and Linux platforms.
  • It supports Sweave and LaTeX.
  • It includes syntax highlighting for R, LaTeX and Sweave.
  • It includes a way to view variables and dataframes.
  • It makes it easy to load and install package, to navigate in the help files and to manage your workspace.
  • It supports code and file name completion.
  • It can be installed on a USB stick.

John Verzani has written a book dedicated to this new interface, Getting Started with RStudio[7] and Jeffrey Racine recommand RStudio for Sweave[8].

RKwardEdit

RKward is an IDE and a GUI for Linux (KDE) (Screenshots). RKWard aims to provide an easily extensible, easy to use IDE/GUI for R. RKWard tries to combine the power of the R-language with the (relative) ease of use of commercial statistics tools.

Eclipse with StatETEdit

Eclipse with the StatET plugin[9] provides an IDE for R.

  • It supports Sweave.

Rattle GUIEdit

Tinn REdit

  • For Windows only
  • Tinn R[12] is a good IDE for Windows users. One can easily define keyboard shortcuts to execute selected R code from Tinn R.

Notepad++ and NpptoREdit

  • For Windows only.

Notepad++[13] and NPPtoR[14] provides syntax highlighting and hotkeys (by default F8) to send lines of code to R. Syntax highlighting can be easily modified using the dialog box to manage user define languages (Menu/View/Use Define Dialog...). NPPtoR provides a method to generate syntax highlighting dynamically (depending on all the available packages in the R environment).

Vi, Vim and GVimEdit

  • Vim and GVim provides syntax highlighting
  • Vim is for advanced users only
  • The Vim-R-plugin allows the communication between Vim and R

Emacs and ESSEdit

  • Emacs with ESS (Emacs Speaks Statistics)[15].
  • Emacs is for advanced users only.
  • For Linux users, you just have to install emacs and ESS using your standard package manager (synaptic, aptitude, yum, etc)
  • For Mac and Windows user, you can have a look at Vincent Goulet's page which has binary with Emacs and ESS[16].
  • For Mac users, Aquamacs Emacs is a good solution. It is an enhancement of the standard Emacs editor.
  • For Windows users, XEmacs is a good solution.


  • Once the installation of Emacs and ESS is done, you just have to open Emacs and open or create a file with extension .R (C-x C-f). ESS will be automatically loaded.
    • C-c M-j evaluates the current line
    • C-c M-r evaluates the current region
    • C-c M-b evaluates the current buffer

WinEdtEdit

  • How to use R for Windows with the RWinEdt extension ? by Andy Eggers[17]
  • WinEdt is not open source
  • WinEdt is for Windows only.
  • Install the RWinEdt package.

gedit with gedit-r-pluginEdit

  • For Linux users only.
  • There is also a plugin for gedit called gedit-r-plugin. This can be installed using Synaptic or any other package manager on a linux platform.

Customizing REdit

R profileEdit

R can be customized using the Rprofile file. On Linux, this file is stored in the home directory. You can edit it by running the following command in a terminal :

$ gedit ~/.Rprofile

If you use some packages very often, you can load them systematically using the Rprofile file. You can also change the default options.

OptionsEdit

The function options() without any argument show all options

> options()

The linguistic and encoding options can be modified using Sys.setlocale() :

> Sys.setlocale()
[1] "fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/en_US.UTF-8"

By default, error messages are in the local language. However, it is possible to set them in English using Sys.sentev()

Sys.setenv(LANGUAGE='en')

ReferencesEdit

  1. This section was imported from the Wikiversity project Installation, How to use R course
  2. Updating R from R (on Windows) – using the {installr} package
  3. Portable R http://sourceforge.net/projects/rportable/
  4. http://jgr.markushelbig.org/JGR.html
  5. http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/
  6. rstudio.org
  7. John Verzani "Getting Started with RStudio An Integrated Development Environment for R", O'Reilly Media, September 2011
  8. Jeffrey Racine, (forthcoming), "RStudio: A Platform Independent IDE for R and Sweave," Journal of Applied Econometrics.
  9. StatET : http://www.walware.de/goto/statet
  10. Rattle : http://rattle.togaware.com/
  11. Graham J Williams. Rattle: A Data Mining GUI for R. The R Journal, 1(2):45-55, December 2009
  12. Tinn stands for Tinn Is Not Notepad http://www.sciviews.org/Tinn-R/
  13. Note that Notepad++ can be installed on a USB stick http://sourceforge.net/projects/notepadpluspe/
  14. NPPtoR is also a portable software http://sourceforge.net/projects/npptor/
  15. ESS : http://ess.r-project.org/
  16. Vincent Goulet Emacs page http://vgoulet.act.ulaval.ca/emacs
  17. http://www.people.fas.harvard.edu/~aeggers/RWinEdt_installation.pdf
Previous: Data types Index Next: Packages