Installing R for Windows

An R and S-PLUS Companion to Applied Regression

John Fox

Basic Information

The current version of R is version 2.5.1. R and associated software and documentation are available at the CRAN (Comprehensive R Archive Network) web site, and at many 'mirror' sites around the world. The link to the R for Windows installer provided here is to a CRAN mirror in North America, if you are not in North America (or even if you are), you may prefer to use a mirror closer to you. Further information about R is available on the R home page.

CRAN contains pre-compiled 'binary' distributions of R for Windows, Macintosh, and some Linux systems, and of contributed packages for Windows and Macintosh systems. There are also 'source' files for R and for contributed packages; these need to be compiled before they can be used, and are for users who want to run R on a system for which precompiled binaries are not available, or who want to make changes to R or to a package; building R and packages on typical Linux and and Unix systems is straightforward. Windows binary packages are distributed in .zip files.

Once you install R for Windows, a great deal of information, including manuals and FAQ (Frequently Asked Questions) lists, is accessible through the Help menu.

Step 1: Download the current version of R for Window

The Windows distribution of R, which runs under Windows 95 and more recent versions of Windows, is available as a standard Windows installer, called R-2.5.1-win32.exe. This version includes the basic R system, several recommended packages, the R manuals, help files in several forms, a basic Tcl/TK installation (for graphical user interfaces), and software that you will need if you want to write your own R packages.R-2.5.1-win32.exe is fairly small in comparison to typically bloated Windows software, but it is still a large file (29 Mbytes) to download over a slow  connection to the Internet.

For use in a class, the instructor can prepare a CD-ROM with R-2.5.1-win32.exe and other R files (such as the pre-compiled contributed packages); it is even possible to prepare a Windows installer for customized versions of R.

After downloading R-2.5.1-win32.exe or otherwise acquiring a copy of this file, you may run the installer in the normal manner, for example, by double-clicking on the R-2.5.1-win32.exe file in the Windows Explorer. During the installation, most users may safely select all of the defaults (simply clicking the Next button on each screen). There are potential installation issues for users of  Windows Vista due to the security provisions in that OS; Windows Vista users should consult the relevant section of the R for Windows FAQ

Step 2: Download and install additional R packages

If you have installed R as described in Step 1, there will be an R icon on your desktop. Run R by double-clicking this icon (or from the Start menu).

R comes with several useful contributed packages. To see them, enter the command library() in the R Console. In addition, you will want to install the car package associated with the R and S-PLUS Companion, and possibly other packages as well.

The easiest way to install additional packages (such as the car package) is from the Packages menu in R:
  • Run R, if it is not already running.
  • Select Packages Install package(s) from CRAN ... . A window will open asking you to pick a CRAN mirror site for your session; following this, a window will open with the various packages that are available on CRAN. 
  • Using the mouse, select the package or packages that you want to install; if you want to install more than one package, hold down the Control key while you click on the additional packages. 
  • When you are finished selecting packages, click the OK button. 
You can also install binary packages from another source, such as a CD-ROM:
  • Select Install package(s) from local zip files ... from the Packages menu in R. 
  • Navigate to the location of the zip file containing the package.
  • Click the Open button.
Even if you have installed R from a CD-ROM, however, you are probably better off installing packages directly from CRAN (as long as you have an Internet connection): Package files are not very large, and installing from CRAN insures that you get the latest version.

Note, as well, that you can periodically update all of your installed packages to the latest version by selecting Update packages from CRAN from the Packages menu in R. Only newer versions of packages than those currently installed on your system will be downloaded and installed. It is a good idea to do this periodically, including in a newly installed version of R, since some of the recommended packages bundled with the R distribution may have been updated since R-2.5.1-win32.exe was created.

Note for Windows Vista users: If you have installed R into the default location in C:\Program Files\, then you will have trouble installing packages unless you use the default Administrator account. See the relevant section of the R for Windows FAQ

Step 3: Optionally Customize R

R is highly configurable. If you have installed R on a single-user Windows system, I suggest that you customize R by editing the configuration files, which are located in the etc subdirectory off the main R directory. These are plain-text (ascii) files, which should be edited with a text editor such as Windows Notepad. Before editing a configuration file it is a good idea to make a copy of it, attaching the file-type .dist to the copy; then, if you hopelessly mess up a file, you can easily return to the original version.

You will find the following configuration files :
  • Rconsole, logically enough, contains settings, such as colors and fonts, for the R Console. You probably will not want to change these settings.
  • Rdevga contains font selections for graphics windows. Again, you probably will not want to alter the font selections.
  • rgb.txt contains named red-green-blue color definitions. You can alter the standard definitions or add your own, but there is probably no reason to do so.
  • contains R commands to be executed at the start of each session, such as options(show.signif.stars=FALSE). Place the commands on separate lines in . Remember to save the file after you have finished editing it. (Note that prior to R 2.2.0, this file was called Rprofile in the Windows version of R.)
 The standard R installation is configured reasonably, but there are a few things that you may wish to change:
  • I suggest that you use a programming editor with R, as described in Chapter 1 of the R and S-PLUS Companion. The current version of R for Windows includes a basic "script" editor (you can open a script window via the File menu), but a good programming editor provides additional features such as syntax highlighting and delimiter mataching.
    • Uwe Ligges has contributed special configuration files and instructions for using the WinEdt editor with R. Note that WinEdt is shareware, not free software.
    • Alternatively, you may wish to try the free "Emacs speaks statistics" (ESS); I have prepared detailed information about installing, configuring, and using ESS with the Windows version of XEmacs. Note: Because of the availability of the Tinn-R editor (immediately below), I am no longer maintaining this information about ESS, and it may be out of date.
    • Finally, José Cláudio Faria has made available a very nice, free Windows programming editor for R called Tinn-R; I believe that this is currently the best choice for most Windows users of R. To use Tinn-R, you have to run R for Windows in "single-document interface" (SDI) mode, in which different R windows are independent rather than being contained in a master window as in the default "multiple-document interface" (MDI). You can select the SDI during the installation process or edit the Rconsole file afterwards (see below).
  • As described in Chapter 1 of the R and S-PLUS Companion, it is desirable to keep saved workspaces for different projects in separate directories. This assumes, of course, that you choose to save the R workspace; I believe that most users are well advised to start each R session with a fresh workspace, and therefore should not save the workspace between sessions. A simple way to save project-specific workspaces is to create a menu-item to be used with the context menu for the right mouse button in Windows Explorer:
  1. Download the file RunRHere.reg to your hard disk.
  2. Using a plain-text (ascii) editor, edit RunRHere.reg to reflect the location of the file Rgui.exe on your system.
  3. In the Windows Explorer, double-click on the file RunRHere.reg . WARNING: This procedure makes a change to your Windows registry, which is inherently risky. Make sure that your system is backed up, and that the contents of RunRHere.reg are correct before proceding. If this makes you nervous, don't do it.
Once you have completed this procedure, you can run R in a particular directory by right-clicking on the directory in Windows Explorer and selecting Run R from the context menu. Then, when you save the workspace, it will be saved in this directory. (RunRHere is taken from a suggestion posted by Dieter Menne to the R-help email list.)
  • An alternative to the preceding approach is to create an icon on the Windows desktop for each project:
  1. Right-click on the current R icon on the desktop, and (holding down the right mouse button) drag the icon to another location on the desktop. Release the mouse button and select Copy Here from the context menu.
  2. Alternatively, in Windows Explorer, navigate to the bin subdirectory under the main R directory; right-click on Rgui.exe , and drag this file to the desktop; select Create Shortcut(s) Here from the context menu.
  3. Right-click on the newly created icon. Select Properties from the pop-up menu. Edit the Start in field on the Shortcut tab so that it contains the directory for the project. Edit the name field on the General tab to contain the name that you want to assign to the project. Click OK when you are finished.
  1. Make a copy of the R icon by right-clicking on the icon and dragging it to a new location on the desktop. Release the mouse button and select Copy Here.
  2. Right-click on the new icon and select Properties. Edit the Target field on the Shortcut tab to read "C:\Program Files\R\R-2.5.1\bin\Rgui.exe" --sdi (including the quotes exactly as shown, and assuming that you've installed R to the default location). Then edit the shortcut name on the General tab to read something like R 2.5.1 SDI .

Last modified:  16 August 2006 by John Fox <jfox AT >