Install R, RStudio, and R packages

This 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). 

# To install the 'EconGeo' package, follow these 5 steps:

# 1. Install the most recent version of R: https://www.r-project.org/

# 2. Install the 'EconGeo' package by running the code below (directly in the R console)

install.packages("devtools")
library(devtools)
devtools::install_github("PABalland/EconGeo", force = T)

# 3. Load the 'EconGeo' package by running the code below (directly in the R console)

library (EconGeo)

# 4. Become familiar with the package by running some basic functions (see the examples in the documentation)

# 5. If you need help on a specific function - type '?' before the function's name. For instance, for help on the relatedness.density function run the following code in the R console:

?relatedness.density

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

For the network workshop we will 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("devtools")
library(devtools)
devtools::install_github("PABalland/EconGeo", force = T)

Step 7

If you see an error message (you do not have permission to write to the R-3.3.1\library directory): 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:\Program Files\R

  • 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