Setup R and RStudio

Following along with tutorials in

Learn how to setup R and RStudio and follow along with the eReefs tutorials.

R and RStudio setup

Download and install R (the programming language) and RStudio (the integrated development environment) following these RStudio installation instructions.

Linux dependencies

RStudio makes it easy to install the required R packages, but it can’t install any system-level (Linux) dependencies. These need to be installed separately.

On Ubuntu, you can install those dependencies using the following command:

sudo apt-get install libnetcdf-dev libgdal-dev libproj-dev libgeos-dev libudunits2-dev libsqlite3-dev libcurl4-openssl-dev libcurl4-openssl-dev libssl-dev libxml2-dev libfreetype-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libpng-dev libtiff5-dev libjpeg-dev

Running R code in RStudio

Open RStudio and create a new project: File > New Project > New Directory > New Project. Click New File in the bottom-right panel, and choose R Script. The new R file will open in the main panel of RStudio.

You can now copy / paste code chunks from the tutorial page, by clicking the button in the right corner of each chunk. Make sure you run them in order.

Installing R packages

You may encounter the situation where an R package used in the tutorials have not yet been installed on your machine. You can install the package manually by running the following command:

install.packages("<package name>")  # replace <package name> with the name of the R package you wish to install