How to display line numbers for code chunks in rmarkdown HTML and PDF

前端 未结 2 1421
甜味超标
甜味超标 2020-12-11 02:25

how do i display the line numbers of my code chunk with rmarkdown?

```{r}
   x <- 1:10
   y <- x^2
   plot(x,y)
```

and i would like

2条回答
  •  抹茶落季
    2020-12-11 02:54

    You can produce two code blocks: one for the presentation and another, hidden, for execution.

    ---
    output:
      pdf_document:
         highlight: haddock
    ---
    
    ```{#numCode .R .numberLines}
       x <- 1:10
       y <- x^2
       plot(x,y)
    ```
    
    ```{r results='asis', echo=FALSE}
       x <- 1:10
       y <- x^2
       plot(x,y)
    ```
    

    Note: If you replace pdf_document with html_document, you must provide the metadata "highlight".

提交回复
热议问题