Line numbers for code blocks

I'd like to have line numbers for code blocks in my R Markdown documents. When I follow Yihui Xie's cookbook, I think I should end up with this code:

title: "Untitled"
author: "Unauthored"
date: "0/20/2020"
    highlight: tango

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

## Line numbers

```{r, attr.source='.numberLines'}
if (TRUE) {
  x <- 1:10
  x + 1

But it gives me no line numbers:

Is it me?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

When running this example, I correctly get the numbered lines

See how the code block is indented like yours but with numbers before. It is possible that this is due to your theme note correctly appearing on your computer. I think that because if you deactivate numbered lines you got this

With the code block not indented.

Try to highlight with your mouse what is before your code block

Thank you, good to know it is me.

I did the highlighting trick before, which revealed that the numbers are actually missing. I also tried with three different browsers.

Is there anything else I could try?

What is your rmarkdown version and pandoc version ?

I was running rmarkdown 2.1 and pandoc Just updated to rmarkdown 2.3, but no luck.

I tried with the pandoc version shipped with RStudio first, 2.7.3, and it's working.
Tried then with last pandoc 2.10.1 and I can reproduce your issue. I will look into it.

Thanks for diving into this!

Adding rmarkdown::find_pandoc(version = '2.7.3') to the setup chunk did the trick.

Shall I mark your response as the solution, or shall I wait for you to look into the problem with more recent pandoc versions?

Let's keep it open until the issue is resolved

I'll post back when it is. Thanks for the report !

1 Like