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'
![](https://static.wixstatic.com/media/c5611b_e7723d1fb9d649b8a0f50ca851405996~mv2_d_1210_1210_s_2.png/v1/crop/x_0,y_0,w_1210,h_847/fill/w_876,h_612,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/c5611b_e7723d1fb9d649b8a0f50ca851405996~mv2_d_1210_1210_s_2.png)
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.
![](https://static.wixstatic.com/media/c5611b_ddfca879c88944aa87b89b2cece4cb88~mv2.png/v1/crop/x_0,y_0,w_1518,h_841/fill/w_876,h_485,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/c5611b_ddfca879c88944aa87b89b2cece4cb88~mv2.png)
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
![](https://static.wixstatic.com/media/c5611b_c2c7080cab124b7fa087f1d55863d246~mv2.png/v1/crop/x_44,y_0,w_1216,h_742/fill/w_872,h_532,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/c5611b_c2c7080cab124b7fa087f1d55863d246~mv2.png)
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).
![](https://static.wixstatic.com/media/c5611b_998e2656a693408189e3a92605a5be36~mv2.png/v1/fill/w_865,h_532,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/c5611b_998e2656a693408189e3a92605a5be36~mv2.png)
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)
![](https://static.wixstatic.com/media/c5611b_7b81fb8a4d9d4af5b2d92122b649beb0~mv2.png/v1/fill/w_830,h_468,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/c5611b_7b81fb8a4d9d4af5b2d92122b649beb0~mv2.png)
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
![](https://static.wixstatic.com/media/c5611b_32ed1c75cb6246b4a0c0583f3af59796~mv2.png/v1/fill/w_830,h_468,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/c5611b_32ed1c75cb6246b4a0c0583f3af59796~mv2.png)