```{r setup}
#| include: false

library(emoji)
```

## Course material

<br> 

All course material is available on GitHub: 

<br>

> [https://arca-dpss.github.io/quarto-school/](https://arca-dpss.github.io/quarto-school/)


## Schedule

<br>


| Date       | Time                | Room   |
|--------------------|---------------------|--------|
| Monday, July 21    | 2:30 pm – 5:30 pm   | SC20   |
| Tuesday, July 22   | 2:00 pm – 5:00 pm   | SC20   |
| Wednesday, July 23 | 2:00 pm – 5:30 pm   | SC20   |
| Thursday, July 24  | 2:00 pm – 5:30 pm   | SC20   |
| **Friday, July 25**    | **9:00 am – 12:00 pm**  | **SC20**   |

# Quarto 

## What is it?

<br>


[R Markdown](https://rmarkdown.rstudio.com/), next generation

<br>


All based on [knitr](https://cran.r-project.org/web/packages/knitr/index.html) to execute R code

. . . 

> Analyze. Share. Reproduce. You have a story to tell with data—tell it with Quarto.

. . . 

In this course: RStudio! 

Download R: [https://cran.r-project.org/bin/windows/base/](https://cran.r-project.org/bin/windows/base/)

Download RStudio: [https://posit.co/download/rstudio-desktop/](https://posit.co/download/rstudio-desktop/)

## R Markdown


`markdown` is a markup languange: Programming language where formatting is handled by chunk codes, `tags` 

<br>

| Format       | Extension |
|--------------|-----------|
| Markdown     | `.md`     |
| R Markdown   | `.Rmd`    |
| Quarto       | `.qmd`    |


## markup languages 

:::{.panel-tabset}

## HTML

```{r}
#| out-width: 90%
#| fig-align: center
#| fig-cap: HTML editor
knitr::include_graphics("img/html-example.png")
```


## LaTeX

```{r}
#| out-width: 90%
#| fig-align: center
#| fig-cap: LaTex Editor
knitr::include_graphics("img/latex.png")
```

:::

## WYSIWYG languages

What You See Is What You Get

The text is modified with built-in command, you can see immediately the changes: 

```{r}
#| out-width: 80%
#| fig-align: center
#| fig-cap: Word
knitr::include_graphics("img/word.png")
```


## Why? 

Using knitr, it allows for integrating analyses, text, and graphs in a single document: 

- Replicability 

- Tydiness 

- Convenience 

Create dynamic content with Python, R, Julia, and Observable

## An example

:::{.r-stack}

:::{.fragment .fade-in-then-out}

```{r}
#| echo: false
#| out-width: 100%
#| warning: false
#| message: false

library(ggplot2)

ggplot(rock, 
         aes(x = peri, y = perm, size = area)) + geom_point()
```

:::
::: {.fragment .fade-in-then-out}
But you are asked to change the ggplot theme!

Using a WYSIWYG: 

1. Re-open R

2. Find the data again 

3. Re-run the analysis 

4. Plot the results with the requested changes 

5. Save the plot 

6. Import the plot in the document
:::

::: {.fragment .fade-in-then-out}
Here.. just add `+ theme_light()` to the code and render it again

```{r}
#| echo: false
#| out-width: 300%
#| warning: false
#| message: false


library(ggplot2)
library(plotly)

ggplot(rock, 
         aes(x = peri, y = perm, size = area)) + geom_point() + theme_light()

```


:::

:::

## {auto-animate="true"}

```{r}
#| echo: true

graph = ggplot(rock, 
         aes(x = peri, 
             y = perm, size = area)) + 
  geom_point() + theme_light()
graph
```

## {auto-animate="true"}

```{r}
#| echo: true

graph = ggplot(rock, 
         aes(x = peri, 
             y = perm, size = area)) + 
  geom_point() + theme_light()
library(plotly)
ggplotly(graph)
```


# Let's get started `r emoji("partying face")`

## Be tidy: `Rstudio` Project

Create a directory that can be re-organized in subdirectories, allowing for a conveninet managment of all the files (data, images, bibliography)


File $\rightarrow$ New project: 

```{r}
#| fig-align: center
#| out-width: 79%

knitr::include_graphics("img/project1.png")
```



## 

:::: {.columns}

::: {.column width=50%}
What?
```{r}
#| fig-align: center
#| out-width: 79%
knitr::include_graphics("img/project2.png")
```

:::

::: {.column width=50%}
Where?
```{r}
#| fig-align: center
#| out-width: 79%
knitr::include_graphics("img/project3.png")
```

:::

::::

# GitHub (also known as "Nerdstagram")

##

```{r}
#| out-width: 25%
#| out-height: 20%
#| fig-align: center

knitr::include_graphics("img/gh.png")

```


[https://github.com/](https://github.com/)

It is needed to create sharable html documents 

It allows to share your code (and your projects) with others



## Create an account

::: {.r-stack}

::: {.fragment .fade-out}

```{r}
#| out-width: 90%
#| fig-align: center
knitr::include_graphics("img/ghMail.png")
```
:::

::: {.fragment .fade-in-then-out}

```{r}
#| out-width: 90%
#| fig-align: center
knitr::include_graphics("img/ghMail1.png")
```
:::

:::

## Username and password

Please, choose something that you can remember

<br>


```{r}
knitr::include_graphics("img/ghMailpwd.png")
```


Solve the CAPTCHA and submit


## GitHub Desktop 

[https://desktop.github.com/](https://desktop.github.com/)

<br>


```{r}
knitr::include_graphics("img/ghDesk.png")
```


## Install Git 

GitHub desktop allows for an "inderect" connection between RStudio and GitHub 

[Git](https://gitforwindows.org/) allows for a direct connection between RStudio and GitHub 

Just follow the default installation

. . . 

If it worked (you might have to close RStudio and restart your PC): 

```{r}
#| fig-align: center
#| out-width: 80%
knitr::include_graphics("img/check.png")
```


## "Clone" an existing repository I 

From GitHub desktop: 

**Add Local Repository** $\rightarrow$ search for the directory of the R project to publish on GitHub

```{r out.width="80%"}
knitr::include_graphics("img/banner-git.png")
```


## "Clone" an existing repository II

Option: **create a repository** 

```{r}
#| fig-align: center
knitr::include_graphics("img/clone-repo.png")
```


Flag the option "Initialize the repository with a `README`

## Did it work? 

Navigate to you GitHub profile on [https://github.com/](https://github.com/) and to your repositories: 

```{r}
#| fig-align: center
knitr::include_graphics("img/myGit.png")
```



## The repository must be public

```{r out.width="90%"}
knitr::include_graphics("img/public.png")
```


# Learn by doing



## 

To explore the potentials of integrating code chunks, analyses, and results in one unique document, we need to work with a real dataset: 

> [Download dataset from the course website](https://arca-dpss.github.io/quarto-school/)


```{r}
#| echo: false
#| eval: true

data = read.csv("C:/Users/Ottavia/Documents/GitHub/quarto-school/data/dataset.csv")
```


Dataset details: 

- ``r colnames(data)[1]``: Anxiety score — higher scores indicate higher levels of anxiety

- ``r colnames(data)[2]``: Cognitive flexibility score — higher scores indicate greater flexibility

- ``r colnames(data)[3]``: Whether the person practices mindfulness daily, `no` vs. `yes`

- ``r colnames(data)[4]``: Type of sport activity practiced, `r unique(data[,4])`



## Your turn!

1. Create a default R project for this course 

2. Create a GitHub account (and install Git and GitHub desktop)

3. Add the project you have created for this course to your GitHub account

4. Check whether the repository is available online and make it public 

5. Place the dataset in a subfolder named `data`

. . . 

<br>

Final check: Download the file from the [course website](https://ottaviae.github.io/quarto-school/), open it in your newly created project and: 

```{r}
#| out-width: 100%
knitr::include_graphics("img/render.png")
```

