forked from TheoreticalEcology/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1-GettingStarted.qmd
122 lines (82 loc) · 3.98 KB
/
A1-GettingStarted.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Getting Started {#sec-gettingstarted}
## 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](https://cran.r-project.org/bin/macosx/) (not the x86_64 version))
## 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:
::: panel-tabset
## Windows
```{r, eval=FALSE}
install.packages("keras", dependencies = TRUE)
keras::install_keras()
```
## Linux
```{r, eval=FALSE}
install.packages("keras", dependencies = TRUE)
keras::install_keras()
```
## MacOS-M1/M2
If you have already installed anaconda/miniconda, please uninstall it first!
1. Download the ARM miniconda version from [here](https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.pkg) 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
```
4. Open R, install the package 'reticulate' by running `install.packages('reticulate')` and run:
```{r}
#| eval: FALSE
reticulate::use_condaenv("r-reticulate")
```
::: callout-tip
If the installation has failed, run the following command:
```
python -m pip install --upgrade numpy
```
:::
## MacOS-Intel
```{r, eval=FALSE}
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.
## 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:
```{r chunk_chapter1_2, eval=FALSE}
install.packages("torch")
library(torch)
torch::install_torch()
```
## EcoData
We use data sets from the EcoData package. To install the package, run:
```{r chunk_chapter1_3, eval=FALSE}
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
```{r, eval=FALSE}
devtools::install_github(repo = "TheoreticalEcology/EcoData",
dependencies = FALSE, build_vignettes = FALSE)
```
## 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.
```{r chunk_chapter1_4, code=xfun::read_utf8('dependencies.R'), eval=FALSE}
```
## 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
```
## 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'](https://theoreticalecology.github.io/AdvancedRegressionModels/1A-GettingStarted.html#assumed-r-knowledge) from the advanced statistic course.