Install R, RStudio, and R packages

This short tutorial will guide you in the installation of:
- R : a programming language and software environment for statistical computing and graphics
- RStudio: a user-friendly interface for R
- R packages: collection of R functions

1. Install R

R is a programming language and software environment for statistical computing and graphics. It is free, runs on all major operating systems (Windows, Unix and MacOS), contains advanced statistical routines not yet available in other software (in network analysis for instance) and has state-of-the-art graphics capabilities.

Step 1

Visit the R webpage: http://www.r-project.org/ and click ‘download R’

Step 2

Choose the closest CRAN mirror (server) to your location. If you are in Utrecht for instance, you will click on ‘http://cran-mirror.cs.uu.nl/’. If there is no CRAN for your location it’s ok, just find the closest (distance slightly affects download time but any server can do the job.

Step 3

Choose the R version that fits your OS (Windows, Unix or MacOS). Then download and install R on your laptop. Make sure to install the latest version of R (i.e. the most recent one).

2. Install RStudio

R is the software that does all the computation. But we will use an interface to make our life easier. This software is called RStudio.

Step 4

Download RStudio Desktop by visiting https://www.rstudio.com/products/rstudio/download/. Again, choose the one that corresponds to you OS. Install RStudio on your laptop (latest version).

3. Install R packages

R packages are set of functions & codes that have been defined by developers to solve specific problems. For instance, computing network statistics require several lines of complex coding. The R package ‘igraph’ allows you to compute network statistics in a single line of coding that can be as simple as ‘degree’.

Step 5

  • Open RStudio
  • You should see 4 windows (to see the first one, click on the green ‘+’ button below ‘file’ and select ‘R script’)
  • Within the R console (bottom-left window) type: install.packages(“INSERT.PACKAGE.NAME”). For instance, if you want to install the “igraph” package, simply type: install.packages(“igraph”)
  • You will be asked to select your local mirror. Again, select the closest to your geographical location
  • Try to load the package: library (igraph)
  • All good? Great, you’re all set !
  • Does not work? Then go to step 7, we’ll fix you up !

Step 6

We will now need to install the igraph, reshape, Matrix, devtools, EconGeo, RSiena, and networkD3 packages. To install all packages, just copy and paste the entire text below in the R console (bottom-left window):

install.packages(“visNetwork”)
install.packages(“htmlwidgets”)
install.packages(“igraph”)
install.packages(“reshape”)
install.packages(“Matrix”)
install.packages(“RSiena”)
install.packages(“networkD3”)
install.packages(“curl”)
install.packages(“EconGeo”)

Step 7

If you see an error message (you do not have permission to write to the R-3.3.1directory): the problem comes from a security setting on your laptop. You can fix that by (1) changing the library directory to a directory where you have writing privileges or (2) changing the security settings on the R folder to “full control”:

  • Select you R folder (not the RStudio one): C:Files
  • Right click for properties
  • Security
  • In “Group or user names” select your name
  • Click “Edit”
  • Select “Full control”
  • Apply and click OK
  • Now go back to step 5 - you should be able to install packages normally

Step 8

Still not working? Well then you use a R notebook from your browser:
- You just need a Google account
- Save this file on your computer
- Go to Google colab
- Then: File -> Open Notebook, upload the econx.ipynb file you saved earlier
- +code, then click on the play button
- You are all set; uou now have a R browser version in which you can run any R code