Here are some brief instructions for installing R on a PC running Windows or Linux (there is also a Mac port of R, but I have never tried it). I like to use Emacs as a programming environment, and you can run R as a subprocess in an Emacs window using the ESS (Emacs Speaks Statistics) package, so I have included pointers and instructions on how to set this up as well, However, you can run R perfectly well without emacs, so you are not obliged to install it.
The main page for R is CRAN (the Comprehensive R Archive Network). The CRAN page has links to ESS, but you may want to consult the main page for ESS. Both of these have links to documentation, including installation instructions that you might find more useful or more complete than these.
If you do decide to install Emacs and ESS, there is one thing that you must know. Ideally you will only ever have one Emacs process running at any given time. You can edit as many files as you want all at once in a singe Emacs process (subject only to how much RAM your computer has), so it is wasteful to run more than one instance of Emacs. Moreover, doing all your editing (and whatever else) using just one instance of Emacs makes it simpler to move information from one file or application to another.
Download SetupR.exe from CRAN. Double click on SetupR.exe and follow through with the installation. I suggest that you accept the defaults at every step.
Unless you instructed the installation program to do otherwise, an R icon/shortcut has now been created on your desktop. I would strongly suggest that you change the directory that R starts in to something other than the installation directory. To do this, just right click on the icon and choose "Properties". Then change the "Start in:" entry to an appropriate directory. For example, you might want to first create a directory calledc:\sta4033 and then choose this as the starting directory for R to start in.
At this stage you can test your installation by double clicking on the R icon.
There are two ways to install additional packages for R. You could download the .zip file for the package directly the Windows contributed packages area on CRAN and install them from your hard drive. However, I strongly suggest that instead you install the GNU wget program. This will allow you to make better use of R's builtin facilities for installing and upgrading packages.
To install wget, extract the wget.exe file from wget.zip and save it to a directory on your path. In my case, double clicking on wget.zip brought up Power-Archiver, I highlighted wget.exe, clicked on "Extract", and saved wget.exe to c:\Program Files\GNU\bin, which happens to be on my path.
![]() | In Win9x you must edit c:\autoexec.bat to set your path for future logins. In my case I have added the line
|
Having done this, if you fire up R and type, e.g.,
> install.packages("integrate") |
If you want an integrated environment for editing and running R code, you can install either
Emacs + ESS (all free, GPL'd software), or
WinEdt + R-WinEdt (WinEdt is shareware, $30 for students).
To install Emacs on Windows you should first have a look at the NTEmacs page. Then download the latest version of Emacs for Windows (at the time of this writing this was emacs-20.7) from one of the mirror sites like this one.
I installed the "fullbin" version, so I downloaded emacs-20.7-fullbin-i386.tar.gz. You will also need to have the appropriate utilities for unpacking the archive (you might have these already; otherwise look in the utilities directory of your emacs download site). On my machine I simply unpacked the binary distribution into c:\Program Files\ which created the directory c:\Program Files\emacs-20.7. I then created a shortcut on my windows desktop to c:\Program Files\emacs-20.7\bin\emacs. BTW, the GNU icon for emacs can be found in emacs-20.7\etc\icons.
Instructions for installing ESS can be found at the ESS home page. Be sure to scroll down the instructions for installing under MS Windows (the UNIX instructions won't do you much good). Since I have other emacs extras installed, I have created a directory c:\Program Files\emacs. Within that directory I have a further subdirectory c:\Program Files\emacs\site-lisp, and I put unzipped the ESS package there, creating the directory c:\Program Files\emacs\site-lisp\ess-5.1.18.
Now you need to create the file c:\.emacs with the following lines (modify the paths to match your setup):
(load-file "c:/Program Files/emacs/site-lisp/ess-5.1.18/lisp/ess-site.el")
(setq-default inferior-R-program-name
"c:/Program Files/R/rw1023/bin/Rterm.exe") |
(setq-default inferior-R-program-name "Rterm.exe") |
You will probably want to customize emacs a bit. This is done through the c:\.emacs file. Here is a simple version to get you started. You should modify the various paths appropriately for your setup (use Emacs to edit this file). By the way, anything on a line following a semi-colon is a comment.
![]() | I also installed the gnuserv package. This is not necessary, but in some ways it helps realize the goal of only ever having one emacs process running. If you do not install gnuserv, make sure that the relevant lines are commented out in your .emacs file. |
Once you have everything set up, to run R in Emacs, first start up Emacs and then (with focus in the Emacs window) type M-x R (followed by the Enter key). In case you're wondering, M-x means "Meta-x", which means hold down the "Meta key" and type "x" (sort of like C-x means "Ctrl-x"). On the typical PC keyboard, the "Meta" key is just the "Alt" key.
Download the RPM for the most recent version of R from CRAN. At the time of this writing this was R-base-1.2.3-1.i386.rpm. Then su to root and do the following
rpm -Uvh R-base-1.2.3-1.i386.rpm |
Installing packages is easy. Here's an example showing how to install the integrate package and using some of the options:
[root@localhost RPMS-7.1]# R
*** output deleted ***
> options(CRAN="cran.us.r-project.org")
> install.packages("integrate","/usr/lib/R/library")
*** output deleted ***
Delete downloaded files (y/N)? y
> q()
Save workspace image? [y/n/c]: n |
To install the most recent version of ESS, you can just grab the gzipped tar archive (ESS-5.1.18.tar.gz is the most recent version as of today) from the nearest ESS site, and install it wherever you prefer. Here's a simple installation that will work, assuming you've downloaded ESS-5.1.18.tar.gz to your home directory:
gunzip -c ESS-5.1.18.tar.gz | tar -xvf - cd ess-5.1.18 make |
(load "~/ess-5.1.18/lisp/ess-site") |
There are precompiled binaries for the Debian, Mandrake, and SUSE distributions of linux. If you are using any of these distributions then the installation should be straightforward. Otherwise you should just install R from source. This shouldn't require much more than unpacking followed by "./configure; make; make install".
ESS packages for the three linux distributions mentioned above can be found next to the corresponding R package on CRAN, or you can follow the instructions in the RedHat section for installing ESS from source.
I'm clueless about this, but there is a port of R to the Mac. Check CRAN for details.