R, RStudio and r5r

Software

In this chapter we will guide you through the installation of R, RStudio and the packages you will need for this course, for the macro network models.

R and RStudio1 are separate downloads.

R

You will need R installed on your computer. R stats (how it is also known) is a programming language and free software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing.

The download links live at The Comprehensive R Archive Network (aka CRAN). The most recent version is 4.5.1, but you can use >= 4.1.x if you already have it installed.

After this installation, you don’t need to open R base. Please proceed to install RStudio.

RStudio

RStudio Desktop is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management.

RStudio is available for free download from Posit RStudio.

R packages

You will need to install some packages to work with the data and scripts in this course.

You can install them in RStudio by searching for them in the Packages tab:

or by running the following code in the console:

install.packages("tidyverse")

install.packages("sf")
install.packages("mapview")
install.packages("osmextract")
install.packages("elevatr")
install.packages("stplanr")
install.packages("h3jsr")
install.packages("od")

install.packages(c("remotes", "devtools", "usethis")) # optional

r5r

The simplest way to install r5r is by running the code below on RStudio Console. This might take a few minutes if this is the first time you install these packages.

pkgs = c("r5r", "accessibility", "rJavaEnv", "interp", "quantreg")

install.packages(pkgs)

# dev version with latest features - optional
utils::remove.packages('r5r')
devtools::install_github("ipeaGIT/r5r", subdir = "r-package")

Java Development Kit

To use the {r5r} package (version v2.0 or higher), you will need to have Java Development Kit (JDK) 21 installed on your computer. There are numerous open-source JDK implementations. The easiest way to install JDK is using the new {rJavaEnv} package in R.

# check version of Java currently installed (if any) 
rJavaEnv::java_check_version_rjava()

## if this is the first time you use {rJavaEnv}, you might need to run this code
## below to consent the installation of Java.
# rJavaEnv::rje_consent(provided = TRUE)

# install Java 21
rJavaEnv::java_quick_install(version = 21)

# check if Java was successfully installed
rJavaEnv::java_check_version_rjava()

Alternatively, you can manually download and install JDK 21.

Footnotes

  1. We will use RStudio, although if you already use other studio such as VScode, that’s also fine.↩︎