1  Getting Started

1.1 R System

Make sure you have a recent version of R (>=4.0, ideally >=4.2) and RStudio on your computers. For Mac users, if you have already a M1/M2 Mac, please install the R-ARM version (see here (not the x86_64 version))

1.2 TensorFlow and Keras

If you want to run the code on your own computers, you need to install TensorFlow / Keras for R. For this, the following should work for most people:

install.packages("keras", dependencies = TRUE)
keras::install_keras()
install.packages("keras", dependencies = TRUE)
keras::install_keras()

If you have already installed anaconda/miniconda, please uninstall it first!

  1. Download the ARM miniconda version from here and install it

  2. Open the terminal (e.g. by pressing cmd+whitespace and search for ‘terminal’)

  3. Run in the terminal (not in R!):

conda create -n "r-reticulate" python=3.10 
conda install -c apple tensorflow-deps 
python -m pip install tensorflow-macos 
python -m pip install scipy
  1. Open R, install the package ‘reticulate’ by running install.packages('reticulate') and run:
reticulate::use_condaenv("r-reticulate")
Tip

If the installation has failed, run the following command:

python -m pip install --upgrade numpy
install.packages("keras", dependencies = TRUE)
keras::install_keras()

This should work on most computers, in particular if all software is recent. Sometimes, however, things don’t work well, especially the python distribution often makes problems. If the installation does not work for you, we can look at it together. Also, we will provide some virtual machines in case your computers / laptops are too old or you don’t manage to install TensorFlow.

1.3 Torch for R

We may also use Torch for R. This is an R frontend for the popular PyTorch framework. To install Torch, type in R:

install.packages("torch")
library(torch)
torch::install_torch()

1.4 EcoData

We use data sets from the EcoData package. To install the package, run:

devtools::install_github(repo = "TheoreticalEcology/EcoData", 
                         dependencies = TRUE, build_vignettes = TRUE)

The default installation will install a number of packages that are useful for statistics. Especially in Linux, this may take some time to install. If you are in a hurry and only want the data, you can also run

devtools::install_github(repo = "TheoreticalEcology/EcoData", 
                         dependencies = FALSE, build_vignettes = FALSE)

1.5 Further Used Libraries

We will make huge use of different libraries. So take a coffee or two (that will take a while…) and install the following libraries. Please do this in the given order unless you know what you’re doing, because there are some dependencies between the packages.

install.packages("abind")
install.packages("animation")
install.packages("ape")
install.packages("BiocManager")
BiocManager::install(c("Rgraphviz", "graph", "RBGL"))
install.packages("coro")
install.packages("dbscan")
install.packages("dendextend")
install.packages("devtools")
install.packages("dplyr")
install.packages("e1071")
install.packages("factoextra")
install.packages("fields")
install.packages("forcats")
install.packages("glmnet")
install.packages("glmnetUtils")
install.packages("gym")
install.packages("kknn")
install.packages("knitr")
install.packages("iml")
install.packages("lavaan")
install.packages("lmtest")
install.packages("magick")
install.packages("mclust")
install.packages("Metrics")
install.packages("microbenchmark")
install.packages("missRanger")
install.packages("mlbench")
install.packages("mlr3")
install.packages("mlr3learners")
install.packages("mlr3measures")
install.packages("mlr3pipelines")
install.packages("mlr3tuning")
install.packages("paradox")
install.packages("partykit")
install.packages("pcalg")
install.packages("piecewiseSEM")
install.packages("purrr")
install.packages("randomForest")
install.packages("ranger")
install.packages("rpart")
install.packages("rpart.plot")
install.packages("scales")
install.packages("semPlot")
install.packages("stringr")
install.packages("tfprobability")
install.packages("tidyverse")
install.packages("torchvision")
install.packages("xgboost")
install.packages("tidymodels")

devtools::install_github("andrie/deepviz", dependencies = TRUE,
                         upgrade = "always")
devtools::install_github('skinner927/reprtree')
devtools::install_version("lavaanPlot", version = "0.6.0")

reticulate::conda_install("r-reticulate", packages = "scipy", pip = TRUE)
reticulate::conda_install("r-reticulate", packages = "tensorflow_probability", pip = TRUE)

1.6 Linux/UNIX systems have sometimes to fulfill some further dependencies

Debian based systems

For Debian based systems, we need:

build-essential
gfortran
libmagick++-dev
r-base-dev

If you are new to installing packages on Debian / Ubuntu, etc., type the following:

sudo apt update && sudo apt install -y --install-recommends build-essential gfortran libmagick++-dev r-base-dev

1.7 Reminders About Basic Operations in R

Basic and advanced knowledge of R is required to successfully participate in this course. If you would like to refresh your knowledge of R, you can review the chapter ‘Reminder: R Basics’ from the advanced statistic course.