diff --git a/NEWS.md b/NEWS.md index 7a62963de8..a7f1add2bb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -26,7 +26,7 @@ - `imgur_upload()` requires fewer package dependencies now. It only requires the **curl** package; **httr** is no longer required, and **xml2** has become optional. -- Progress bar includes the chunk location (`chunk-name @ file:line`) (@zeehio, #2232) +- Progress bar includes the chunk location (`chunk-name @ file:line`) when `options(knitr.progress.linenums = TRUE)` is set. (@zeehio, #2232) # CHANGES IN knitr VERSION 1.42 diff --git a/R/output.R b/R/output.R index d833b5449b..d361b6a1d2 100644 --- a/R/output.R +++ b/R/output.R @@ -291,16 +291,20 @@ process_file = function(text, output) { labels = unlist(lapply(groups, function(g) { if (is.list(g$params)) g[[c('params', 'label')]] else '' })) - linenums <- unlist(lapply(seq_along(groups), function(i) { - curr_lines <- current_lines(i) - sprintf( - "%s:%d-%d", - knit_concord$get('infile'), - curr_lines[1], - curr_lines[2] - ) - })) - labels_linenums <- paste(labels, linenums, sep = " @ ") + if (getOption("knitr.progress.linenums", default = FALSE)) { + linenums <- unlist(lapply(seq_along(groups), function(i) { + curr_lines <- current_lines(i) + sprintf( + "%s:%d-%d", + knit_concord$get('infile'), + curr_lines[1], + curr_lines[2] + ) + })) + labels_linenums <- paste(labels, linenums, sep = " @ ") + } else { + labels_linenums <- labels + } if (progress) { pb_fun = getOption('knitr.progress.fun', txt_pb) pb = if (is.function(pb_fun)) pb_fun(n, labels_linenums)