International College of Digital Innovation, Chiang Mai University
October 30, 2024
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:
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.
menu Tools
\(\rightarrow\) Global Options...
FiraCode Font
Fira Code is a popular monospaced font designed for programming. Here are some key features and information about it:
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.
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.
Open Source: Fira Code is open-source and can be freely used and modified. It is available on platforms like GitHub.
Cross-Platform: It can be used on various operating systems, including Windows, macOS, and Linux.
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.
You are install R program.
You are install RStudio.
You are install Quarto.
Warning
This interactive slide cannot run Quarto files (.qmd).
Follow these steps:
Open RStudio: Launch RStudio from your applications or programs menu.
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.
---
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.
After save file, we can render to recieve the output/report
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
a YAML header
formatted text
one or more code chunks.
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: "30 Oct 2024"
date-format: long
format: html
theme: superhero
toc: true
---
YAML settings depend on the type of output. You can read more details on the Quarto website.
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.
Goal | Quarto | output |
---|---|---|
bold text | **text** | text |
italic text | *text* | text |
strikethrough | ~~text~~ | |
superscript | text^2^ | text2 |
subscript | text~2~ | text2 |
Try it in your Quarto
---
title: "RStudio and Quarto"
author: "Somsak Chanaim"
institute: "International College of Digital Innovation, CMU"
date: "30 Oct 2024"
date-format: long
format: html
theme: superhero
toc: true
---
## section
contents...
### subsubsection
contents...
#### subsubsubsection
contents...
##### subsubsubsubsection
contents...
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.
Results
item 1
item 2
sub-item 2
sub-item 3
item 3
item 4
Codes
| 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~ |
Results
Goal | R markdown | output |
---|---|---|
bold text | **text** | text |
italic text | *text* | text |
strikethrough | ~~text~~ | |
superscript | text^2^ | text2 |
subscript | text~2~ | text2 |
Example
If your output contains mathematical symbols, you need to know \(\LaTeX\) commands.
\[ \cos^2(\theta) +\sin^2(\theta) =1 \]
You can use the online service from many website, example hostmath
you can also include links to webpages or other links in your document. Use the following syntax to create a clickable link to an existing webpage.
Example
Result
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
In R markdown, you can put R code in this
Results
[1] 4
We will show some useful chuck options ans you must do it in your R markdown.
Hide source code:
Does not run this chuck
Without setting
Setting by
fig-height: \<number\>
fig-width: \<number\>
GUI
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 |
Example: If we have chuck code
We can use variable values to display or compute within the content.
The value of a + b is \(^\backprime\)r a + b\(^\backprime\).
The value of a / b is \(^\backprime\)r a / b\(^\backprime\).
The value of a + b is 4.
The value of a / b is 0.3333333.
You will get the addins “Write new R markdown of YAML file
The goal of DT is to help you build interactive table.
Example
Rstudio after version 1.4+or after the year 2021, we can use the Visual Markdown Editing menu to product quarto output.
[1] https://docs.posit.co/ide/user/
[2] https://www.quarto.org
[3] https://github.com/tonsky/FiraCode
[4] https://www.hostmath.com