# Rizz in ten minutes

Use Rizz's playful vocabulary to learn ordinary R. You'll calculate scores, read a CSV, and make a chart. This lesson takes about ten minutes **after setup**. It uses only the packages shipped with R and a synthetic dataset bundled in this folder; no internet connection is needed during the lesson.

## Setup (not included in the ten minutes)

Install R 4.0 or newer and the Rizz package, then in R run `rizz::rizz_install_cli()` and follow its PATH instructions. Run `rizz tutorial` to find this folder. Copy the **whole folder** into a writable directory and change your terminal to that copy:

```sh
cd /path/to/your/copied/tutorial
rizz scores.rizz
```

The complete program prints a summary and writes `scores.png`. `rizz scores.R` runs the equivalent plain R program. If you haven't installed the launcher, use `Rscript /path/to/rizz.R scores.rizz` from the copied tutorial directory.

The source snippets below can also be entered in `rizz`'s interactive console. Every numbered stage supplies the setup it needs. The console retains variables between submissions; complete scripts start fresh. Use `:quit` to leave the console. Ordinary R calls such as `sum()` and `read.csv()` remain available in Rizz.

## 1. Calculate scores (two minutes)

**Rizz**

```r
scores <- as.aura(c(42, 67, 100))
sum(scores)
mean(scores)
sum(scores >= 60)
```

**Equivalent R**

```r
scores <- as.integer(c(42, 67, 100))
sum(scores)
mean(scores)
sum(scores >= 60)
```

Expected results: total **209**, average approximately **69.66667**, and **2** passing scores. A vector holds several values; `scores >= 60` tests each score. `sum()` counts the true comparisons.

Allocation and conversion are different:

| Rizz | Equivalent R | Result |
| --- | --- | --- |
| `aura(3)` | `integer(3)` | Three zeros: `0L, 0L, 0L` |
| `as.aura(3)` | `as.integer(3)` | One integer: `3L` |
| `typeof(3)` | `typeof(3)` | `"double"` |
| `typeof(3L)` | `typeof(3L)` | `"integer"` |

Predict what `length(aura(4))` and `length(as.aura(4))` return, then try them. The answers are 4 and 1. `typeof()` deliberately uses R's type names.

## 2. Define a function (two minutes)

**Rizz**

```r
label_score <- cook(score) {
  vibe(score >= 60) {
    serve("passed")
  } big_yikes {
    serve("keep practicing")
  }
}
label_score(67)
```

**Equivalent R**

```r
label_score <- function(score) {
  if (score >= 60) {
    return("passed")
  } else {
    return("keep practicing")
  }
}
label_score(67)
```

The result is `"passed"`. Keep `} big_yikes {` on the same line, just as R expects `} else {`. In the console, `?cook` explains the syntax and provides an example. Enter the whole braced function, using the continuation prompt, before calling it.

## 3. Read a CSV (three minutes)

**Rizz and R — the same code**

```r
data <- read.csv("scores.csv")
data
sum(data$score)
```

Expected table:

| name | score |
| --- | --- |
| A | 42 |
| B | 67 |
| C | 100 |

The total is again 209. `data$score` selects a column. If R cannot open the file, run `getwd()` and `list.files()`; change to the copied tutorial directory containing `scores.csv`, or give its full path. Installing Rizz does not change your working directory.

## 4. Plot and experiment (three minutes)

**Rizz and R — the same code**

```r
data <- read.csv("scores.csv")
png("scores.png", width = 900, height = 600)
barplot(data$score, names.arg = data$name, ylim = c(0, 100),
        col = "#418264", xlab = "Learner", ylab = "Score",
        main = "Scores: A 42, B 67, C 100")
abline(h = 60, lty = 2)
invisible(dev.off())
```

Open `scores.png`. It shows three labeled bars with heights 42, 67, and 100, and a dashed passing threshold at 60. In Positron or the browser playground, omit the `png()` and `dev.off()` lines to show the plot directly; the plotted values are identical.

Change the threshold to 70. Predict the number of passing scores, then check `sum(data$score >= 70)`: **1**. The dashed line is a visual reference; changing it alone does not change the earlier calculation.

## R compatibility and help

- A `.rizz` file enables slang automatically. An ordinary `.R` file stays R.
- A leading `# rizz` explicitly enables slang in any source file. `--r` and `--rizz` override automatic selection.
- Slang aliases are reserved in Rizz expressions. For a literal variable called cap, use backticks: `` `cap` <- 8; `cap` ``.
- Strings and comments are literal: `"fr"` stays text. `fr` and `cap` are `TRUE` and `FALSE`.
- `rizz keywords` lists aliases; `?cook` and `?aura` provide help in the console.
- Try `vibef(fr)` to see a typo diagnostic. Correct it to `vibe(fr) spill("fixed")`.

You can now edit `scores.rizz`, run `rizz check scores.rizz` without executing it, and run your edited program. `rizz transpile scores.rizz -o generated.R` lets you inspect ordinary R with the same behavior.
