Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2232: Trace chunk location in progress bar #2250

Merged
merged 4 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down