Introduction to Quarto
RStudio
Using Project
RStudio Layout
Locate the following panes:
- Console
- Source
- History
- Help
Recommended Options
- Tools –> Global Options –>
- Set “Save workspace to .RData on exit” to “No”.
R Basics
Install R Packages
See https://twitter.com/visnut/status/1248087845589274624
# Install the tidyverse "meta" package
# install.packages("tidyverse")
# Install the here package
# install.packages("psych")
!!! Don’t you dare include any install.packages()
statements in your homework !!!
Load a Package
# Uncomment the code below to load the tidyverse package
# library(tidyverse)
Built-In Data
data(bfi, package = "psych") # make the "bfi" data set available for use
head(bfi, 10) # show the first 10 rows of data
Quarto
- Open-source scientific and technical publishing system
- Next-generation version of R Markdown
Elements of Quarto
See https://quarto.org/docs/get-started/hello/rstudio.html
- YAML header
- Code chunks
- Markdown text
YAML
- Update your name in the
author
field - Change the option from
toc: false
totoc: true
- Insert today’s date using the
date
field
Markdown Text
See https://quarto.org/docs/authoring/markdown-basics.html
Bold
**Bold**
italic
*italic*
code
`code`
Link to USC
[Link to USC](https://www.usc.edu)
Header
# Level 1
## Level 2
### Level 3
Unordered list
- item 1
- item 2
- item 2a
Ordered list
- item 1
- item 2
- item 2a
Equations (LaTeX)
Inline: \(Y_i = \beta_0 + \beta_1 X_i + e_i\)
Display:
\[\rho = \frac{\tau^2}{\tau^2 + \sigma^2}\]
Inline Code
`r pi` The value of $\pi$ is
The value of \(\pi\) is 3.1415927
Code Chunks
Content to be interpreted by R engine
1 + 1
[1] 2
<- c(1, 2, 6, 8) # create a vector `v1`
v1 3] # extract 3rd element of v1 v1[
[1] 6
# extract the `A2` column, and compute the median
median(bfi$A2)
[1] NA
Chunk Options
echo: false
: Do not show the input commandfig-width
,fig-height
: Size of figure
library(ggplot2)
ggplot(bfi, aes(x = A2)) +
geom_bar()
Warning: Removed 27 rows containing non-finite values (`stat_count()`).
Change the aspect ratio of the graph above to 1:1
Rendering
format
:html
,pdf
,docx
, etc- If running into problems for PDF, enter the following to the Terminal:
Terminal
quarto install tool tinytex
- Try also
revealjs
!
Note: Different R sessions are used for the console and for knitting
Exercise
Download the Rmd file, then do the following
- Complete Ex1 above.
- Complete Ex2 above.
- Type this equation in LaTeX: https://www.gstatic.com/education/formulas2/472522532/en/cronbach_s_alpha.svg. Make sure you get all the subscripts right.
- Install and load the
modelsummary
package, run the following, and write down what the chunk does. You’ll need to seteval: true
(or remove the line) so the chunk runs.
# Install and load the modelsummary package first; otherwise, it won't run
library(dplyr)
library(modelsummary)
datasummary(O1 + O2 + O3 + O4 + O5 ~
Factor(gender, levelnames = c("Males", "Females")) *
+ SD),
(Mean data = bfi)
- Run the following and find out what the code chunk does.
%>%
bfi select(A1:C5) %>%
datasummary_correlation()
- Run the following and find out what the code chunk does.
%>%
bfi select(E1:E5) %>%
::alpha() psych
- Run the following and find out what this code chunk does.
library(tidyr)
%>%
bfi select(N1:N5) %>%
pivot_longer(cols = N1:N5, names_to = "item", values_to = "score") %>%
ggplot(aes(x = score)) +
geom_bar() +
facet_wrap(~ item)
Render the document to a PDF output.
Submit the knitted PDF to Blackboard.