How to display code chunk when the corresponding list item is displayed?

Viewed 44

In the following RMarkdown MWE:

---
title: "Untitled"
output: 
 beamer_presentation:
   slide_level: 2
---

# Paragraph

## Slide

Hello

>- This is the first item
>- This is the second item

  ```{r}
  a <- 2+2
  ```

I want the code chunk to be displayed hwne the second list item is displayed in the resulting PDF file, instead the code chunk is displayed when the first item is displayed.

1 Answers

Include the code within the > block. This works,

---
title: "Untitled"
output: 
 beamer_presentation:
   slide_level: 2
---

# Paragraph

## Slide

Hello

>- This is the first item

>- This is the second item
> 
>   ```{r}
>   a <- 2+2
>   ```

enter image description here

Related