There are three steps to get you running:

  1. Install R for your computer operating system
  2. Install RStudio
  3. Install my recommended extra R packages

Installing R

(These notes were modified from the R Workshop, https://rworkshop.uni.lu/)

R is available for free for Windows, GNU/Linux and MacOS.
My current version is 3.5.2.

R is easiest to use with Rstudio as the graphical user interface. You should also install RStudio, as described below.

Windows

Visit the download page and choose the corresponding installer for your platform. After downloading, double-click on the installer file. Usualy, that is **all* you need to do.

Power users only

You will need Rtools to compile and install some packages, but this is an advanced feature you may not require. Mainly useful when you want to install packages from their source code or bleeding-edge versions from github.

There is no general software/package manager in Windows, but you can install the R library installr. This package provides the updateR() function which takes care of updating your R installation and migrates your installed libraries whenever a major R update is released. Recently, a package has been released which can also help you in this task.

MacOS

You can either browse to the download page or better use the Homebrew package manager.

Robert Rudis wrote a nice blog post about a 100% homebrew r install.

Once homebrew is installed, you can easily install/uninstall many programs with their dependencies and utilities. This requires using the terminal, but is a generally useful skill to learn for MacOS.

To install R using brew type the following in a terminal window:

brew install r

Updates for all your software can be easily performed and will be automatically handled by the following line:

brew update; brew upgrade

GNU/Linux

All Linux distributions are bundled with a great package manager such as dpkg or rpm. Visit the appropriate webpage for your distribution here.

After you get the correct entry in your package manager, it should quite easy:

sudo apt-get install r-base r-base-dev

Other packages can be installed within Rstudio or the R console.

Install Rstudio

Rstudio is an Integrated Development Editor. It provides a convienent GUI for R that goes well beyond the standard R console. You need to install R first, because Rstudio needs to find your R version. The free-version contains everything you need.

Visit the download page and choose the corresponding installer for your platform. Currently, the latest version is 1.1.456.

See the blog entry about this major release.

Of note, version 1 introduced new features, such as inline code results to get chunks and execution one after the other.

Open RStudio

They are 4 main panels in rstudio, but as the top-left is for scripting and by default missing, the layout should looks like

Install R packages from the Comprensive R Archive Network (CRAN)

For this course, I have a recommended collection of packages. You can install them all by entering the following line in the Console panel. This will take a while. Go have a coffee.

source("http://datavis.ca/courses/RGraphics/R/install-pkgs.R")

Manual installation

On the bottom-right panel, 5 tabs are present:

  • Files
  • Plots
  • Packages
  • Help
  • Viewer

Click on the Packages tab (1.) and select the select the Install button (2.). Type devtools in (3.)

Of note, devtools is handy when you want to install a development version, for example if a bug was fixed but the package not yet submitted to CRAN.

devtools::install_github("tidyverse/dplyr")

Package updates

R packages are frequently updated. If you want to keep your R up to date, just use update.packages():

update.packages()

You could also use the green Update button next to the Install (located in the Packages tab). The advantage is that you can check which package you would like to update and look at the actual changes by clicking on the NEWS link.

Testing your installation

Copy / paste the code below into the Console, and you should obtain your first R plot.

plot(mpg ~ wt, data=mtcars)

If not, please contact me with the error produced and the output of

sessionInfo()
## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] compiler_3.5.2  magrittr_1.5    tools_3.5.2     htmltools_0.3.6
##  [5] yaml_2.2.0      Rcpp_1.0.0      stringi_1.2.4   rmarkdown_1.11 
##  [9] knitr_1.21      stringr_1.4.0   xfun_0.4        digest_0.6.18  
## [13] evaluate_0.13