Skip to content

Commit 510a5c4

Browse files
committed
close #99 via a new chunk option fig.keep (to filter out undesired plots)
1 parent 9f39fc2 commit 510a5c4

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: litedown
22
Type: Package
33
Title: A Lightweight Version of R Markdown
4-
Version: 0.7.4
4+
Version: 0.7.5
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGES IN litedown VERSION 0.8
22

3+
- Added a new chunk option `fig.keep` to select plots to be kept in a code chunk (thanks, @Gabrielforest, #99). See https://yihui.org/litedown/#sec:option-fig for documentation.
4+
35
- The chunk option `results = 'hide'` will imply `collapse = TRUE`, i.e., when text output is hidden, the source blocks will be merged (thanks, @jangorecki, #87).
46

57
- `fuse(text = '# text')` will be treated as Markdown input instead of R code input (thanks, @chuxinyuan, #102).

R/fuse.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ reactor(
10971097
attr.source = NULL, attr.output = NULL, attr.plot = NULL, attr.chunk = NULL,
10981098
attr.message = '.plain .message', attr.warning = '.plain .warning', attr.error = '.plain .error',
10991099
cache = FALSE, cache.path = NULL,
1100-
dev = NULL, dev.args = NULL, fig.path = NULL, fig.ext = NULL,
1100+
dev = NULL, dev.args = NULL, fig.path = NULL, fig.ext = NULL, fig.keep = TRUE,
11011101
fig.width = 7, fig.height = 7, fig.dim = NULL, fig.cap = NULL, fig.alt = NULL, fig.env = '.figure',
11021102
tab.cap = NULL, tab.env = '.table', cap.pos = NULL,
11031103
print = NULL, print.args = NULL, time = FALSE,
@@ -1121,15 +1121,15 @@ eng_r = function(x, inline = FALSE, ...) {
11211121
return(fmt_inline(res, x$math))
11221122
}
11231123
args = reactor(
1124-
'fig.path', 'fig.ext', 'dev', 'dev.args', 'message', 'warning', 'error',
1124+
'fig.path', 'fig.ext', 'fig.keep', 'dev', 'dev.args', 'message', 'warning', 'error',
11251125
'cache', 'print', 'print.args', 'verbose'
11261126
)
11271127
if (is.character(args$fig.path)) args$fig.path = paste0(args$fig.path, opts$label)
11281128
size = list(width = opts$fig.width, height = opts$fig.height)
11291129
# if fig.dim is provided, override fig.width and fig.height
11301130
if (length(dm <- opts$fig.dim) == 2) size[] = as.list(dm)
11311131
# map chunk options to record() argument names
1132-
names(args)[1:2] = c('dev.path', 'dev.ext')
1132+
names(args)[1:3] = c('dev.path', 'dev.ext', 'dev.keep')
11331133
args = dropNULL(args)
11341134
args$dev.args = merge_list(size, opts$dev.args)
11351135
args$cache = list(

docs/02-fuse.Rmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,13 @@ Chunk options for plot files include:
777777
the option `dev.args` (@sec:option-dev), e.g.,
778778
`dev.args = list(width = 9, height = 7)`.
779779
780+
- `fig.keep`: Indices of plots to be kept. The indices can be either numeric
781+
(positive or negative integers) or logical. Negative integers and false
782+
values will remove the corresponding plots. For example, if a code chunk
783+
generates 3 plots, `c(1, 3)`, `-2`, and `c(T, F, T)` are equivalent ways for
784+
`fig.keep` to remove the second plot. The special value `fig.keep = 'last'`
785+
means to keep the last plot only.
786+
780787
- `fig.path`: A path prefix for plot files. This prefix, joined by the chunk
781788
label and the plot number, will be the actual plot file path. For example,
782789
for `fig.path = 'figures/'` and a chunk with the label `foo`, the *i*-th

0 commit comments

Comments
 (0)