Skip to content

Commit

Permalink
Show line numbers in progress bar when options(knitr.progress.linenum…
Browse files Browse the repository at this point in the history
…s = TRUE)
  • Loading branch information
zeehio committed Apr 25, 2023
1 parent ea94e81 commit d9d1613
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 14 additions & 10 deletions R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d9d1613

Please sign in to comment.