Practical 3

Quarto and tables

  1. Create a new Quarto document in RStudio. Use the default format (HTML) and ensure that the document includes a title and author.

  2. Write a short introduction (1-2 sentences) explaining the purpose of the document.

  3. Add a Markdown section demonstrating headings, bold, italics, and lists. For example:

    • Bold text
    • Italic text
    • A numbered list
    • A bullet point list
  4. Insert an R code chunk that calculates the mean and standard deviation of a numeric vector. Ensure the chunk is set to echo: true so the code appears in the rendered document.

    ```{r}
    #| echo: true
    values <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    mean(values)
    sd(values)
    ```
  5. Modify the code chunk options:

    • Add another code chunk that prints a message but set echo: false so the code is hidden but the output is visible.
    ```{r}
    #| echo: false
    print("This message is displayed, but the code is hidden.")
    ```
  6. Create a simple table using the gt package. Load the penguins dataset and display a summary table of species and bill_len.

    ```{r}
    #| message: false
    library(tidyverse)
    library(gt)
    data(penguins)
    
    penguins |>
      select(species, bill_len) |>
      head() |>
      gt()
    ```
    Tip

    Note that gt is simply converting your data frame into a HTML table; it’s not calculating anything like tbl_summary.

  7. Use the tbl_summary function from the gtsummary package to summarise all numeric variables in the penguins dataset by species.

    ```{r}
    library(gtsummary)
    
    penguins |>
      select(species, where(is.numeric)) |>
      tbl_summary(by = species)
    ```
  8. Convert the document to Microsoft Word format by modifying the YAML header at the top of the document. Change format: html to format: docx.

  9. Render the document and verify that the output appears as expected.