\(~~~~~~~~~\)RStudio and Quarto\(~~~~~~~~~\)

Somsak Chanaim

International College of Digital Innovation, Chiang Mai University

July 3, 2025

Why we use RStudio?

RStudio is an integrated development environment (IDE) for R that provides several features and tools to enhance the R programming experience. Here are some reasons why many users choose to use RStudio:

User-Friendly Interface and Integrated Tools

  • Intuitive Layout: RStudio has a well-organized interface.

  • Syntax Highlighting: It offers syntax highlighting, which helps in reading and writing code more easily.

  • Script Editor: You can write and edit R scripts, the features like code completion and error checking.

  • Console: The built-in console allows you to run R commands interactively.

  • Viewer Pane: You can visualize plots and interactive outputs within the IDE.

RStudio Interface

Set Up Your Styles

menu Tools \(\rightarrow\) Global Options...

FiraCode Font

Fira Code

Fira Code is a popular monospaced font designed for programming. Here are some key features and information about it:

Features of Fira Code:

  1. Ligatures: Fira Code includes programming ligatures, which are special combinations of characters that are rendered as single symbols (e.g., !=, ->, ==). This makes code more readable and visually appealing.

  2. Monospaced: As a monospaced font, each character takes up the same amount of horizontal space, which is ideal for aligning code and making it easier to read.

  3. Open Source: Fira Code is open-source and can be freely used and modified. It is available on platforms like GitHub.

  4. Cross-Platform: It can be used on various operating systems, including Windows, macOS, and Linux.

  5. Clear and Readable: The font is designed to be legible at different sizes, making it suitable for long coding sessions.

Quarto is an open-source, next-generation publishing system designed for creating dynamic documents,

  • reports

  • presentations

  • websites

  • dashboard

  • Shiny

  • books

  • ETC.

Allowing for a more flexible and powerful way to create documents that integrate code, text, tables, videos ,and visualizations depending on the output.

Check your computer.

  1. You are install R program.

  2. You are install RStudio.

  3. You are install Quarto.

Warning

This interactive slide cannot run Quarto files (.qmd).

To start using Quarto with RStudio

Follow these steps:

  1. Open RStudio: Launch RStudio from your applications or programs menu.

  2. Create a New Quarto Document:

    • In RStudio, go to the top menu and select: File \(\rightarrow\) New File \(\rightarrow\) Quarto Document

    • This will create a new .qmd file where you can write your Quarto content.

Note

In this course, we will focus on creating HTML documents/reports with Quarto.

For the final project, you will learn how to create a dashboard with Quarto.

  1. Write Your Quarto Content: You can start writing your document using Markdown syntax, and include R code chunks where needed. Here’s a simple example:
---
title: "My First Quarto Document"
author: "Your name"
institute: "International College of Digital Innovation, CMU"
date: Oct 13, 2024
date-format: long
format: html
---

## Introduction

This is my first Quarto document.

```{r}
summary(cars)
```

Tip

Copy codes and put into your computer \(\rightarrow\) save file \(\rightarrow\) render.

Quarto Process

Quarto works the same way as R Markdown

Quarto works the same way as R Markdown

After save file, we can render to recieve the output/report

Quarto anatomy

You can render a qmd file in RStudio into HTML, docx and pdf etc. The output based on your set up

Normally for each Quarto file is composed of 3 main components

  1. a YAML header

  2. formatted text

  3. one or more code chunks.

YAML header

YAML header is processed in many stages of the rendering process and can influence the final document in many different ways.

A typical YAML header looks like this, and contains basic metadata about the document and rendering instructions:

---
title: "RStudio and Quarto"
author: "Somsak Chanaim"
institute: "International College of Digital Innovation, CMU"
date: "June 26, 2025"
date-format: long
date-modified: now
format: html
theme: superhero
toc: true
---

YAML Parameter Explanation

title: "RStudio and Quarto"
  • title: The main title of the document. Displayed prominently at the top of the output file and used in the browser tab.
author: "Somsak Chanaim"
  • author: The name of the person who wrote the document. This may appear under the title depending on the format.
institute: "International College of Digital Innovation, CMU"
  • institute: The organization or affiliation of the author. It can be shown with the author name in the document’s header.
date: "June 26, 2025"
  • date: The publication or creation date of the document. It can be static (as written here) or dynamically updated.
date-format: long
  • date-format: Controls the formatting of the date.

    • long means a format like “June 26, 2025”
    • Other options: short (e.g., 6/26/2025), medium, full
date-modified: now
  • date-modified: Automatically sets the “last modified” date to the current date/time when the document is rendered.
format: html
  • format: Specifies the output format.

  • html: Renders the document as a web page. Suitable for publishing online with themes, interactivity, and responsive design.

  • pdf: Converts the document into a print-ready PDF using LaTeX. This is ideal for academic papers, reports, and materials that require precise layout and styling.

  • docx: Outputs a Microsoft Word document. Useful for collaborative editing, administrative reports, and situations where users prefer Word formatting.

  • pptx: Creates a PowerPoint presentation. Each section or slide in your document becomes a slide in the .pptx file. Useful for formal presentations that require PowerPoint compatibility.

  • revealjs: Generates an HTML slideshow presentation using the Reveal.js framework. Great for interactive, browser-based presentations with animations, code, and charts.

  • dashboard: Builds a web-based dashboard layout with multiple panels and sections (like plots, tables, and text). Useful for showcasing interactive reports and data visualizations.

Each format serves a different purpose depending on the audience and delivery method of the content. You can also configure many appearance and behavior options specific to each format.

theme: superhero
  • theme: The visual style of the HTML document.

    • superhero is a dark, bold theme from Bootswatch.

Another list of theme name from quarto click here

toc: true
  • toc: Enables a Table of Contents in the output.

    • Helps readers navigate through the sections of the document.

Formatted text

One of the great things about Quarto is that you don’t need to rely on your word processor to bring your R code, analysis and writing together. Quarto is able to render (almost) all of the text formatting that you are likely to need such as italics, bold, strike-through, super and subscript as well as bulleted and numbered lists, headers and footers, images, links to other documents or web pages and also equations.

Text format

Goal Quarto output
bold text **text** text
italic text *text* text
strikethrough ~~text~~ text
superscript text^2^ text2
subscript text~2~ text2

Headings

## section
### subsubsection
#### subsubsubsection
##### subsubsubsubsection

Try it in your Quarto

---
title: "RStudio and Quarto"
author: "Somsak Chanaim"
institute: "International College of Digital Innovation, CMU"
date: "03 Jul 2025"
date-format: long
format: html
theme: superhero
toc: true
---
## section
contents...

### subsubsection
contents...

#### subsubsubsection
contents...

##### subsubsubsubsection
contents...

Only for Slide Presentations (PPTX or revealjs)

  • ##: Starts a new slide with a title.

  • ---: Starts a new slide without a title.

Lists

If you want to create a bullet point list of text you can format an unordered list with sub items. Notice that the sub-items need to be indented.

Codes

- item 1

- item 2

    - sub-item 2

    - sub-item 3

- item 3

- item 4





Or


* item 1

* item 2

    * sub-item 2

    * sub-item 3

* item 3

* item 4

Results

  • item 1

  • item 2

    • sub-item 2

    • sub-item 3

  • item 3

  • item 4

Tables

| Goal          | R markdown | output  |
|---------------|------------|---------|
| bold text     | \**text**   | **text**  |
| italic text   | \*text*     | *text*  |
| strikethrough | \~\~text~~   | ~~text~~  |
| superscript   | text\^2^    | text^2^ |
| subscript     | text\~2~    | text~2~ |
Goal R markdown output
bold text **text** text
italic text *text* text
strikethrough ~~text~~ text
superscript text^2^ text2
subscript text~2~ text2

Generate Tables Quickly

Copy a table from Excel or Google Sheets, paste it into tablesgenerator, and generate the corresponding Markdown code.

Add an image code

Code

![put some text here](path-to-image-here)


pic 1

![Dr. Somsak](mypic.png)


pic 2

![We are learning R programming to create data visualizations.](https://myweb.cmu.ac.th/somsak.chanaim/888152/image/course.png)

pic 1

Dr. Somsak

Dr. Somsak

pic 2

We are learning R programming to create data visualizations.

We are learning R programming to create data visualizations.

Remark

path-to-image-here: You should place your image in the same folder as your .qmd file or create a separate folder for images. This makes it easier to manage and insert image files in the same way.

Note: path-to-image-here can also be a URL.

Equations

If your output contains mathematical symbols, you need to know \(\LaTeX\) commands.

Code

 
$$ \cos^2(\theta) +\sin^2(\theta) =1 $$
 

Result

\[ \cos^2(\theta) +\sin^2(\theta) =1 \]

There are many online services you can use, such as hostmath

Callout

In Quarto, a callout is a special block used to highlight content such as tips, warnings, notes, or important information.

Basic Syntax

::: {.callout-note}
## Title (Optional)
This is a note callout.
:::

Result

Title (Optional)

This is a note callout.

Callout Types (Styles)

Type Class Use case
note .callout-note For additional information
tip .callout-tip Helpful suggestions or shortcuts
important .callout-important Key concepts to remember
warning .callout-warning Caution before proceeding
caution .callout-caution Potential risks or pitfalls

With or Without Icons

::: {.callout-tip icon=true}
## Helpful Tip
You can use `filter()` from the `dplyr` package to select rows.
:::

::: {.callout-warning icon=false}
## Be Careful
Don't overwrite your original data without backup!
:::

🎥 Embedding a YouTube Video in Quarto HTML or Revealjs

To embed a YouTube video in an HTML page or a slide of a Quarto revealjs presentation, you can use shortcodes

Example Code:

{{< video https://www.youtube.com/watch?v=_f3latmOhew&t=12s width="900" height="500" >}}

Result

🎥 Tabset in Quarto HTML or Revealjs

A tabset is a user interface element that lets you organize related content into separate tabs within the same section of a page. Only one tab’s content is visible at a time, and users can switch between tabs by clicking on the tab labels.

Why use tabsets?

  • To save space by not showing everything at once

  • To group related information without creating separate sections or pages

  • To improve readability and user experience, especially in HTML documents, revealjs or dashboards

::: {.panel-tabset}

## Tab A

- Content, code, video, etc. 


## Tab B

```{r}
1+1

```
- Content, code, video, etc. 


:::
  • Content, code, video, etc.
1+1
[1] 2
  • Content, code, video, etc.

Column

A column is a vertical section of content placed side by side with other columns. In Quarto, columns help you organize content into multiple parts horizontally within a page or slide.

Why Use Columns?

  • To make content easier to compare

  • To improve layout and readability

  • To present information side by side (e.g., code + output, text + plot)

::::{.columns}

:::{.column width="50%"}
**Instructor**

Dr.Somsak Chanaim

somsak.c@icdi.cmu.ac.th
:::

:::{.column width="50%"}
**Course details**

Day: Mon and Th

Time: 2.45-4.15 PM.

Room: ICB1211
:::

::::

Instructor

Dr.Somsak Chanaim

somsak.c@icdi.cmu.ac.th

Course details

Day: Mon and Th

Time: 2.45-4.15 PM.

Room: ICB1211

Code chunk

https://bookdown.org/yihui/rmarkdown-cookbook/ This part is about set up your R code, you can

  • changing our language engine

  • modifying chunk options, which can be global, local, or engine-specific;

  • set up outputs

how to use code chunk

In R markdown, you can put R code in this

```{r}
2+2
```

Results

[1] 4

Chunk Options

We will show some useful chuck options ans you must do it in your R markdown.

Hide source code:

```{r}
#| echo: false
1+1
```

Does not run this chuck

```{r}
#| eval: false
1+1
```

Setting the height and width of the graph

Without setting

Codes

```{r}
set.seed(1)
x <- rnorm(300)
hist(x)
```

Results

Setting by

fig-height: \<number\>

fig-width: \<number\>

Codes

```{r}
#| fig-height: 9
#| fig-width: 9
set.seed(1)
x <- rnorm(300)
hist(x)
```

Results

Add caption from plot

In the chuck code use command

fig-cap = "any caption word"

```{r}
#| fig-cap: 'The histogram'
set.seed(1)
x <- rnorm(300)
hist(x)
```

The histogram

The histogram

Chunk code setup with tool in RStudio

GUI

RStudio keyboard shortcuts

RStudio has keyboard shortcuts. A full list can be found under the menu Tools \(\rightarrow\) Keyboard Shortcuts Help. Some of the most useful shortcuts related to Markdown are summarized in Table

Task Windows & Linux macOS
Insert R chunk Ctrl+Alt+l Command+Option+l
Preview HTML Ctrl+Shift+K Command+Shift+K
Knitr document (knitr) Ctrl+Shift+K Command+Shift+K
Compile PDF Ctrl+Shift+K Command+Shift+K
Run all chunks above Ctrl+Alt+P Command+Option+P
Run current chunk Ctrl+Alt+C Command+Option+C
Run current chunk Ctrl+Shift+Enter Command+Shift+Enter
Run next chunk Ctrl+Alt+N Command+Option+N
Run all chunks Ctrl+Alt+R Command+Option+R
Go to next chunk/title Ctrl+PgDown Command+PgDown
Go to previous chunk/title Ctrl+PgUp Command+PgUp

Used result from chuck code or R

Example: If we have chuck code

a <- 1
b <- 3

We can use variable values to display or compute within the content.

Content

The value of a + b is \(^\backprime\)r a + b\(^\backprime\).

The value of a / b is \(^\backprime\)r a / b\(^\backprime\).

Result after render.

The value of a + b is 4.

The value of a / b is 0.3333333.

Some useful package: ymlthis

install.packages("ymlthis")

You will get the addins “Write new R markdown of YAML file

addins ymlthis

addins ymlthis

Create Awesome Table: DT

The goal of DT is to help you build interactive table.

install.packages("DT")

Example

Visual Markdown Editing menu in RStudio

Rstudio after version 1.4+or after the year 2021, we can use the Visual Markdown Editing menu to product quarto output.

The Visual Markdown Editing menu

The Visual Markdown Editing menu

Reference

[1] https://docs.posit.co/ide/user/

[2] https://www.quarto.org

[3] https://github.com/tonsky/FiraCode

[4] https://www.hostmath.com

[5] https://www.tablesgenerator.com/