aos
June 23, 2020, 2:15pm
1
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"
output:
html_document:
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?
system
Closed
July 14, 2020, 2:15pm
2
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
cderv
August 3, 2020, 12:53pm
4
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
aos
August 3, 2020, 1:34pm
5
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?
cderv
August 3, 2020, 1:43pm
6
What is your rmarkdown version and pandoc version ?
aos
August 3, 2020, 2:08pm
7
I was running rmarkdown 2.1 and pandoc 2.9.1.1. Just updated to rmarkdown 2.3, but no luck.
cderv
August 3, 2020, 4:00pm
8
aos:
pandoc 2.9.1.1
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.
aos
August 4, 2020, 7:27am
9
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?
cderv
August 4, 2020, 7:34am
10
Let's keep it open until the issue is resolved
opened 12:38PM - 03 Aug 20 UTC
closed 12:50PM - 21 Aug 20 UTC
bug
For some reason I cannot reproduce the line numbers from the [provided example](… https://bookdown.org/yihui/rmarkdown-cookbook/number-lines.html).
Also see this post: https://community.rstudio.com/t/line-numbers-for-code-blocks/70720
Thank you.
I'll post back when it is. Thanks for the report !
1 Like
cbaylor
January 19, 2021, 3:18am
11
Also experiencing the same issue. I tried adding rmarkdown::find_pandoc(version = '2.7.3')
to the set up chunk but that did not work for me. I get the following:
I am running the latest version of R and R Studio. Was there ever a solution to this one?
cderv
January 19, 2021, 7:22am
12
I can't reproduce - the example in the first post is now working ok.
Open a new Rmd file
Copy paste the code in the first example
Click the knit button
Please check your Rmd file for problematic syntax. The formatting error you encounter is different than the original one.
If you still have an issue, please open a new post or GH issue with a new reproducible example.
Thank you!