Information about R (mostly for Windows)

This page is intended to provide undergraduates with information about R (especially for Windows) which is common to the various modules provided by the Department of Mathematical Sciences which make use of R in one way or another.

The following topics are covered:


Accessing the durham library (and other preinstalled libraries)

If you want to be easily to access the durham library (or the many other libraries preinstalled on drive T: on CIS computers):

If you already have R or Rstudio open, you should now close it and reopen it. You should now be able to type library(durham) without getting an error. There are many libraries pre-installed as well (look in the folder where you found "Setup R for Maths").


Getting your own copy of R for Windows

The best place to get your own copy of R for Windows is the Comprehensive R Archive Network (CRAN) via the UK mirror of CRAN (the latest version of R for Windows may be found in the Windows base binary directory and older versions in the sub-directory old). You may install whichever version suits you but it may be wise to install the same version as currently installed on the IT Service networked PCs; otherwise any differences in behaviour are your problem not ours!


Getting your own copy of RStudio

We strongly recommend the use of RStudio as a front-end to R. First install R and then visit the RStudio download page.


Getting your own copy of the datasets used for teaching at Durham

All (or at least most of) the datasets used for teaching with R in the Department of Mathematical Sciences at Durham are in the R library durham

Windows
To install this library on your own machine (having first installed R using the instructions above), download the latest zip file (built with R 3.0.2 for version 3.0.0 of R onwards) and put it on your hard disk. Then run R (for Windows) on your machine and, from the Packages menu, select Install package from local zip file. You only need to repeat this operation if you download a new version. If the zip file provided doesn't work and you have an older version of R then try the previous version .
MacOS X
Download the latest MacOS version(durham_1.4.tgz) and install from the local file by one of the three following means:
R Menu method
  1. Open R
  2. From the Packages & Data menu, open Package Installer
  3. In the combo box at the top of the new window, change it from "CRAN (binaries)" to "Local binary package"
  4. Click Install... button, locate the file, click open.
R command line method
  1. Open R
  2. Use getwd() and setwd() to make sure you are working in the same directory as the package.
  3. install.packages("durham_1.3.tgz",repos=NULL)
Terminal window method
In a terminal window, do
 R CMD INSTALL durham_1.3.tgz
Linux
Download the latest Linux version and save as a file. Then, in a terminal window, do
 R CMD INSTALL filename 

Now you can access all the datasets in the usual way by typing library(durham), and then, for example, data(hospital) if you want the hospital data. Remember that all the datasets have help files that you can access, for example by typing ?hospital and that a list of available datasets may be obtained by typing data()


Printing a plot

To print a copy of a plot, simply bring the R Graphics window to the front and choose Print from the File menu.


Copying a plot to a Word document

Having produced a plot which is to your taste, you can save a copy of it as part of (say) a Microsoft Word document and then you can print the document. Proceed along the following lines:

Now you can do all the usual things with the Word document like add explanatory text, save the document for future use, and printing.


Peter Craig

Last modified: Tue Oct 25 12:36:17 BST 2016


Valid HTML 4.01 Transitional