3

Can I tell quarto to display the entire code block before it displays all the output? I am writing an example for students and the code block ends with a comment. As it stands when the code runs it prints code, then the output and then the comment code.

library(palmerpenguins)
suppressPackageStartupMessages(library(dplyr))
library(purrr)
suppressPackageStartupMessages(library(janitor))

palmerpenguins::penguins |>
  select(where(~ is.factor(.x) | is.character(.x))) |>
  imap(~ {
    dat <- janitor::tabyl(.x)
    names(dat)[1] <- .y
    dat
  })
# Add a pipe above and use pluck()  to extract a table
# }) |>
# pluck("species")

So I want it to show the entire code block first and then the output. Can I do that or do I need to duplicate those lines and then have it print the code the without executing it and then execute the code without printing it?

itsMeInMiami
  • 2,324
  • 1
  • 13
  • 34

1 Answers1

3

Use results: hold.

---
title: "Untitled"
format: html
---

```{r}
#| results: hold
library(palmerpenguins)
suppressPackageStartupMessages(library(dplyr))
library(purrr)
suppressPackageStartupMessages(library(janitor))

palmerpenguins::penguins |>
  select(where(~ is.factor(.x) | is.character(.x))) |>
  imap(~ {
    dat <- janitor::tabyl(.x)
    names(dat)[1] <- .y
    dat
  })
# Add a pipe above and use pluck()  to extract a table
# }) |>
# pluck("species")
```

rendered output with results: hold

shafee
  • 15,566
  • 3
  • 19
  • 47