4
votes

How do you get rmarkdown to include a code chunk as part of a list?

Example:

  1. Something about some code - you could try this_fun
  2. A more complicated way is to do
    ```{r, eval = FALSE}
    a(
    large(
    nested(function)))
    ```
    And that may suit your use case
  3. Skip it all together

Originally I was using the vanilla ``` code chunk, but that gives up syntax highlighting, and inline gives up highlighting and newlines/indentation. If the code is used as above the list is broken, and the text following the chunk becomes embedded in a weird environment (something like the output formatting).

Anyone know if this can be done?

1

1 Answers

6
votes

Are you looking for that? (Save the following code as Rmd file)

---
title: "Untitled"
output: html_document
---

1. Something about some code - you could try this_fun. 
1. A more complicated way is to do
    ```{r, eval = FALSE}
    a <- function() { # whole chunk indented by 4!
      return(2)
    }
    print(a())
    ```
    And that may suit your use case
1. Skip it all together

It look like that: enter image description here