---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
```

## An introduction

This interactive tutorial aims at being a friendly first introduction to R.
You are welcome to revisit it at any time.
Later in the course we will switch from these pre-compiled tutorials to full fledged
notebooks, that allows a great deal more flexibility.

## The basics

At the most basic level, you can use R as a calculator.
For instance, to add 3 and 4:

```{r addition, exercise=TRUE}
3 + 4
```

We might want to save the result of an _expression_ like the one above.
To this end, we can _bind_ the expression to a _name_ using the
`<-` operator.

_**Note**: using the `=` operator (like in Python) will also work, but the `<-` operator is preferred_.

```{r binding, exercise=TRUE}
mysum <- 3 + 4
```

Note that this time R did not print the result of the addition.
Later on you can retrieve the _value_ of the expression by simply typing the name.

```{r binding-ref, exercise=TRUE, exercise.setup="binding"}
mysum
```

In R, _everything has a name_: variables holding data, datasets, and functions.
Not all names are available, though, some are forbidden.
Forbidden names include reserved words like `Inf`, `for`, `else`, `break`, `function`, etc...,
and words for entities like `FALSE`, `NA`, `NULL`.

If you try to use any of these, you will see strange errors, beware!

```{r wrong-binding, exercise=TRUE}
FALSE <- "hello"
```

Variable names cannot contain spaces, unless special care is taken (as we shall see later in the course).
There are a few naming conventions that you will encounter across R libraries:

- snake case naming: variable names with multiple words are named like `a_long_variable_name`
- traditional R naming: words in variables are separated by dots, like `a.long.variable.name`

The second one might be confusing if you come from virtually any other language. Stick to snake case naming.

------------

Now, try to assign to a variable name `y` the value of the expression `3 * x + 2`, where `x` is defined with the value `4`.

```{r exercise-variables-1, exercise=TRUE, exercise.lines=5}

```
```{r exercise-variables-1-solution}
x <- 4
y <- 3 * x + 2
```

### Vectors

