I would like to add code line numbering to the HTML output of my Rmarkdown file. I'd be happy with any approach that uniquely identifies every line of code in the output (e.g., sequential line numbers that increment across the entire document, OR code chunks are identified by their own index, and within these code chunks line numbers start at 1).
I have been unable to achieve this.
Using other stackoverflow answers and this blog post I have gotten line numbers, but they reset with every new chunk.
I have the following Rmd file:
---
output:
html_document:
highlight: kate
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
class.source = "numberLines lineAnchors"
)
```
```{r}
5 + 5
3 * 9
```
```{r}
x <- 5
x * 3
```
Which compiles to:
As you can see, when a chunk is split by output or a new chunk begins, the line numbers reset. What I would like to see is line numbers as 1, 2, 3, 4, instead of 1, 1, 1, 2.