diff --git a/DESCRIPTION b/DESCRIPTION index 5e55eba218..a461864b12 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: knitr Type: Package Title: A General-Purpose Package for Dynamic Report Generation in R -Version: 1.42.7 +Version: 1.42.8 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 38ee44cbdc..89a19bda33 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # CHANGES IN knitr VERSION 1.43 +## NEW FEATURES + +- Progress bar includes the chunk location (`chunk-name @ file:line`) when `options(knitr.progress.linenums = TRUE)` is set (thanks, @zeehio, #2232). + ## BUG FIXES - The chunk option `collapse = TRUE` works with HTML widgets now (thanks, @dmurdoch, #2212). diff --git a/R/utils.R b/R/utils.R index 8ae830a684..77bc556769 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1115,6 +1115,15 @@ str_split = function(x, split, ...) { # default progress bar function in knitr: create a text progress bar, and return # methods to update/close it txt_pb = function(total, labels) { + if (getOption('knitr.progress.linenums', FALSE)) { + nums = sapply(seq_along(labels), function(i) { + paste(current_lines(i), collapse = '-') + }) + labels = sprintf( + '%s%s%s:%s', labels, ifelse(labels == '', '', ' @ '), + knit_concord$get('infile'), nums + ) + } s = ifelse(labels == '', '', sprintf(' [%s]', labels)) # chunk labels in [] w = nchar(s) # widths of labels n = max(w)