diff --git a/NEWS.md b/NEWS.md index c9f277e2cf..5486b44f6b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,7 +20,7 @@ - `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). -- 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 eeefa4da3e..adbc62eb61 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)