Skip to content

Commit

Permalink
when fig.keep is numeric indices, res[which(figs)[keep.idex]] only re…
Browse files Browse the repository at this point in the history
…turns figures in res, and excludes other elements; -which(figs)[-keep.idx] is the correct way to remove the figures that we do not want to keep
  • Loading branch information
yihui committed Dec 4, 2019
1 parent 3c89ab1 commit 53b968c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGES IN knitr VERSION 1.27

## BUG FIXES

- The chunk option `fig.keep` was buggy when taking a numeric vector. The bug was originally introduced in #1265 and discovered in the SO post https://stackoverflow.com/q/59180351/559676.

# CHANGES IN knitr VERSION 1.26

Expand Down
2 changes: 1 addition & 1 deletion R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ block_exec = function(options) {
res = res[-(if (keep == 'last') head else tail)(which(figs), -1L)]
} else {
# keep only selected
if (keep == 'index') res = res[which(figs)[keep.idx]]
if (keep == 'index') res = res[-which(figs)[-keep.idx]]
# merge low-level plotting changes
if (keep == 'high') res = merge_low_plot(res, figs)
}
Expand Down

0 comments on commit 53b968c

Please sign in to comment.