# R Programming/Settings

R Programming
* R Basics
** Introduction
** Sample Session
** Manage your workspace
** Settings and Installation
** Documentation
** Control Structures
** Working with functions
** Debugging
** Using C or Fortran
** Utilities
** Estimation utilities
** Packages
* Data Management
** Data types
** Working with data frames
** Importing and exporting data
** Text Processing
** Times and Dates
* Graphics
** Grammar of graphics
* Publication quality output
* Descriptive Statistics
* Mathematics
** Optimization
** Probability Distributions
** Random Number Generation
* Statistical Core Methods
** Maximum Likelihood
** Method of Moments
** Bayesian Methods
** Bootstrap
** Multiple Imputation
** Nonparametric Methods
* Regression Models
** Linear Models
** Quantile Regression
** Binomial Models
** Multinomial Models
** Tobit And Selection Models
** Count Data Models
** Duration Analysis
* Time Series
* Factor Analysis
* Classification
** Ordination
** Clustering
* Network Analysis
* High Performance Computing
** Profiling R code
** Parallel computing with R
* Appendix
** Sources
** Index
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.

## Installation
### Linux

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 has 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)
Installation with aptitude (Debian, Ubuntu and all linux distributions based on Debian)

### Mac OS

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.

### Windows

(Section source)

#### Download

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.

#### Setup

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.
* On the welcome screen click Next.
* Read or just notice the GNU license, and click Next.
* 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.
* 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.
* In this step you can choose between 2 ways. If you accept defaults, you skip the 3 "extra" steps during installation (see lower).
* You can specify the Start menu folder.
* 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.

#### Update

Updating R on Windows requires several steps:
* Downloading/installing the latest version of R
* 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):
There is also the possibility of using a "global" package library, see here for more details.

### Portable R for Windows

You have a portable version if you want to install R on your USB stick. 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 environment

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.

### Terminal

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

### R Gui

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 Interface

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

#### Poor Man's GUI (pmg)

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

#### Jaguar : Java GUI for R

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

#### R commander

* Rcommander 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.
* Ubuntu users can also install R Commander from the software center.

### Integrated development environment
#### RStudio

RStudio is an integrated development interface for R.
* 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 and Jeffrey Racine recommand RStudio for Sweave.

#### RKward

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 StatET

Eclipse with the StatET plugin provides an IDE for R.
* It supports Sweave.

#### Rattle GUI

* Rattle for Linux, Windows and Mac (screenshots).

#### Tinn R

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

#### Notepad++ and NpptoR

* For Windows only.
Notepad++ and NPPtoR 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 GVim

* 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 ESS

* Emacs with ESS (Emacs Speaks Statistics).
* 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.
* 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
* See John Fox webpage http://web.archive.org/web/20050516104010/http://socserv.mcmaster.ca/jfox/Books/Companion/ESS/ess-xemacs.pdf to learn about Emacs and ESS

#### WinEdt

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

#### gedit with gedit-r-plugin

* 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 R
### R profile

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 :
If you use some packages very often, you can load them systematically using the Rprofile file. You can also change the default options.

### Options

The function options without any argument show all options
The linguistic and encoding options can be modified using Sys.setlocale :
By default, error messages are in the local language. However, it is possible to set them in English using Sys.sentev

## References

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