00-Hello

Ottavia M. Epifania, Ph.D.

Course material


All course material is available on GitHub:


https://arca-dpss.github.io/quarto-school/

Schedule


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?


R Markdown, next generation


All based on knitr 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/

Download RStudio: https://posit.co/download/rstudio-desktop/

R Markdown

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


Format Extension
Markdown .md
R Markdown .Rmd
Quarto .qmd

markup languages

knitr::include_graphics("img/html-example.png")

HTML editor
knitr::include_graphics("img/latex.png")

LaTex Editor

WYSIWYG languages

What You See Is What You Get

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

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

Word

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

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

Here.. just add + theme_light() to the code and render it again

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

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

Let’s get started 🥳

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:

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

What?

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

Where?

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

GitHub (also known as “Nerdstagram”)

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

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

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

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

Username and password

Please, choose something that you can remember


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

Solve the CAPTCHA and submit

GitHub Desktop

https://desktop.github.com/


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

Install Git

GitHub desktop allows for an “inderect” connection between RStudio and GitHub

Git 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):

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

knitr::include_graphics("img/banner-git.png")

“Clone” an existing repository II

Option: create a repository

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/ and to your repositories:

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

The repository must be public

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

Dataset details:

  • anxiety: Anxiety score — higher scores indicate higher levels of anxiety

  • flexibility: Cognitive flexibility score — higher scores indicate greater flexibility

  • mindfulness: Whether the person practices mindfulness daily, no vs. yes

  • activity: Type of sport activity practiced, pilates, altro, yoga

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


Final check: Download the file from the course website, open it in your newly created project and:

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