Skip to content

Commit 11fb1cc

Browse files
committed
Show line numbers in progress bar when options(knitr.progress.linenums = TRUE)
1 parent 741d241 commit 11fb1cc

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎NEWS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
- `imgur_upload()` now recognizes a global option `knitr.imgur.key` or an environment variable `R_KNITR_IMGUR_KEY` for a custom client ID (thanks, @jonthegeek, #2233).
2222

23-
- Progress bar includes the chunk location (`chunk-name @ file:line`) (@zeehio, #2232)
23+
- Progress bar includes the chunk location (`chunk-name @ file:line`) when `options(knitr.progress.linenums = TRUE)` is set. (@zeehio, #2232)
2424

2525
# CHANGES IN knitr VERSION 1.42
2626

‎R/output.R‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,20 @@ process_file = function(text, output) {
291291
labels = unlist(lapply(groups, function(g) {
292292
if (is.list(g$params)) g[[c('params', 'label')]] else ''
293293
}))
294-
linenums <- unlist(lapply(seq_along(groups), function(i) {
295-
curr_lines <- current_lines(i)
296-
sprintf(
297-
"%s:%d-%d",
298-
knit_concord$get('infile'),
299-
curr_lines[1],
300-
curr_lines[2]
301-
)
302-
}))
303-
labels_linenums <- paste(labels, linenums, sep = " @ ")
294+
if (getOption("knitr.progress.linenums", default = FALSE)) {
295+
linenums <- unlist(lapply(seq_along(groups), function(i) {
296+
curr_lines <- current_lines(i)
297+
sprintf(
298+
"%s:%d-%d",
299+
knit_concord$get('infile'),
300+
curr_lines[1],
301+
curr_lines[2]
302+
)
303+
}))
304+
labels_linenums <- paste(labels, linenums, sep = " @ ")
305+
} else {
306+
labels_linenums <- labels
307+
}
304308
if (progress) {
305309
pb_fun = getOption('knitr.progress.fun', txt_pb)
306310
pb = if (is.function(pb_fun)) pb_fun(n, labels_linenums)

0 commit comments

Comments
 (0)