These courses are no longer offered!

Workshops on the R System - Preparation

These notes are intended for anyone planning to attend one of the R courses that I run from time to time, or wanting to test the water for possible attendance at such a course.

In preparation for the Course

Copy down the R binary, install it on your machine, start up R, and start typing!
Windows users: Click here to obtain R

Other systems, click here to look for a binary for your system (MacOS X, some flavours of Linux).

See also the document Installation of R, of R packages, and editor environments

What should I type?

> 1+1
This may suggest some other possibilities!
> nn <- 1:5
Create in the workspace an integer vector nn that holds the values 1,2,3,4,5.
NB: <- is the assignment symbol.
> nn Display (print) the contents of nn
> ls() Show the contents of the workspace. You should see "nn" listed.
> q() End (quit) the session. When asked if you want to save the workspace, make a habit of clicking on "Yes". This saves everything in the workspace into a file (called .RData, for those who really must know) in the working directory.

Before too long, there will be a need to know the path to the working directory. Start R again (the workspace, if saved on the previous exit, gets reloaded), and type:
> ls() Show the contents of the workspace.
> getwd() Get the path to the working directory
If not set or changed from the default, Windows systems may use "C:/Users/Owner/Documents", where "Owner" will be replaced by the user name. Other uses for working directories (there can be as many as you want) will become apparent as the course proceeds.

There are a number of demonstrations to try.
> demo() Gives a list of demos that can be tried
> demo(graphics) Show off the graphics. Press the ENTER key to display the first graph,
and to display each successive graph.

Youtube Videos on R

Go to https://www.youtube.com/off2themovies2

Learning R -- Introductory Notes

Work through chapters 1 and 2, and preferably also chapters 3 and 4:
Chapters 1-4 of Notes
  Click here to get the scripts

NB also Chapter 5, which has examples of the use of R for exploratory data analysis and for regression.
Scripts for Chapter 5

Introductory Documents on the Web

Introductory documents that are available from the web include R for Beginners, by Emmanuel Paradis. Go to https://cran.csiro.au, and click on Documentation to gain access to this and other such documents.

Youtube Videos on R

Go to https://www.youtube.com/off2themovies2 and click on Videos.

Packages that should be installed

Participants should if at all possible arrive with their laptops ready set up for use. After installing R, install also relevant packages. For all courses, install DAAG, ggplot2, latticist, Rcmdr, KernSmooth, scatterplot3d, knitr, car, rgl, memisc, forecast, googleVis and WDI. Several of these packages have a number of dependencies, so that other packages will be installed along with them. With a live internet connection, these can be installed either from the R GUI's Packages menu or (see below) from the command line.

To check, e.g., that DAAG (and dependencies) is properly installed, start R and type, on the command line:
  library(DAAG)

Upon starting up Rcmdr (type library(Rcmdr) at the R command line), the system will offer to install a number of further packages. Assuming a live internet connection, you should accept.

Consider installing also the R packages JGR and Deducer. This GUI has advantages over the R Commander, but is not quite so easy to install, and does not play well with RStudio. I am treating Deducer, at this point, as an optional extra.

For the Learning R: Open Source (Free) Stats Package course, the packages noted above will suffice for the main part of the course.

Futher packages that might usefullly be installed (with dependencies) are: dismo, plyr, dplyr, reshape2, playwith, animation, tm, wordcloud and plotKML, . While not central to the course, these provide impressive abilities. If you are interested in inputting Excel files, install also XLConnect. The XLConnect package requires the Java runtime environment.

For the R for Regression course, install the same packages as for the Learning R ... course.

For the Data Analysis, Graphics and Visualisation Using R course, install (with dependencies): grapheR, dismo, googleVis, ggmap, plotKML, tm wordcloud, likert and shiny.

For the Classification, Modern Regression and Multivariate Exploration course, install gamclass, rattle, and dependencies.

There may be reference to datasets from the packages HistData and SMIR. The datasets will however be available from my website, or from a USB stick or DVD. Other packages to which there may be reference include fortunes, odfWeave, fgui and rpanel.

Installation of packages — menu and command line alternatives

Assuming a live internet connection, packages can be installed from the menu. You will need to select a repository. In Australia, choose an Australian repository. On Windows, the default is to install any dependencies. On MacOS X, be sure to check "Install dependencies".

An alternative is to install packages, for convenience several at the same time, from the command line. For example:.
  install.packages(c("animation", "DAAG", "Ecdat", "forecast", "ggplot2"))
By default, this will install any needed dependencies.

Software that may/should be installed outside of R — RStudio and other

Install RStudio, from https://www.RStudio.com. This Interactive Development Environment (IDE), with its own graphical user interface, has a range of abilities that are helpful for managing and organizing work with R. When RStudio starts up, it will find any installed version of R. A nice addition to the graphics packages noted above is the playwith package. Gtk2 is needed both for playwith and for rattle.

Under Windows, installation of Gtk2 should be straightforward. In case of difficulty, see the website https://gist.github.com/sebkopf/9405675.
(Installation may require administrator privileges. If you try to run rattle or playwith and Gtk2 is not found, there will be a prompt to download and start installation. At least for Windows 7, accepting the offer to download and install has always worked for the tutor.)

For MacOS X, see the instructions given at https://gist.github.com/sebkopf/9405675. Ensure that there is a working version of X11 in the utilities folder, and install Gtk2 from https://https://r.research.att.com/libs/GTK_2.24.17-X11.pkg. Then, from the R command line, type:
> install.packages("RGtk2", depen=T)
This strategy worked for the tutor, with R version 3.2.2 under MacOS 10.10.4.
(Under MacOS X, where problems have been common, the recommended course is to reject any offer to install Gtk2 that is made when trying install software that requires it. Then install Gtk2 outside of R following the instructions above, and install RGtk2 from the R command line.)

Anyone who wishes to experiment with the Deducer GUI, or with the abilities of the XLConnect package for input of Excel files, will require the Java Runtime Environment (JRE). For 64-bit R, consider using the manual install code at Install 64-bit Java JRE for Windows For 32-bit R, be sure to install 32-bit Java JRE. All recent versions of R for the Mac are 64-bit.

Installation of Packages (or even running R) from a DVD

DVDs and memory sticks will however be available at the course from which it will be possible to install, for R version 3.2.0 (or a later version, once available), any packages that are lacking. Additionally, these DVDs will include an R executable that has relevant packages already installed. Once the DVD is in a computer's DVD drive, R can be run from the DVD.

Do you have data that you are happy to expose to wider view?

Contact the presenter with the details. Data that have been used for a published paper may be especially suitable.

Links

Further exercises; and Weaving with R (strictly for those who want some greater challenge!)

Web site for R (CRAN = Comprehensive R Archive Network)

There are further interesting R links here.

John Maindonald's web site

email: john.maindonald AT anu.edu.au
Last updated: 10 October 2015.