Skip to content

Commit 7487b40

Browse files
committed
close #87: results = 'hide' implies collapse = TRUE
1 parent 637bdf0 commit 7487b40

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
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+
Version: 0.7.1
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# CHANGES IN litedown VERSION 0.8
2+
3+
- 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).
4+
15
# CHANGES IN litedown VERSION 0.7
26

37
- `pkg_manual()` will exclude help pages with the keyword `internal` (thanks, @TimTaylor, #78).

R/fuse.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,12 @@ fuse_code = function(x, blocks) {
820820
} else fenced_block(x, a, fence)
821821
}
822822
})
823+
out = dropNULL(out)
823824

824825
# collapse a code block without attributes into previous adjacent code block
825-
if (isTRUE(opts$collapse) && (n <- length(res)) > 1) {
826+
# (also try to collapse for results = 'hide')
827+
collapse = isTRUE(opts$collapse) || res_show == 'hide'
828+
if (collapse && (n <- length(out)) > 1) {
826829
i1 = 1; k = NULL # indices of elements to be removed from `out`
827830
for (i in 2:n) {
828831
if (i - i1 > 1) i1 = i - 1 # make sure blocks are adjacent

examples/test-results-hide.Rmd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`results = 'hide'` should try to collapse output, e.g., merge the source blocks below:
2+
3+
```{r, results = 'hide'}
4+
nrow(iris)
5+
ncol(iris)
6+
iris
7+
```
8+
9+
Other types of output (such as messages) will interrupt the collapsed block:
10+
11+
```{r, results = 'hide'}
12+
nrow(iris)
13+
message(ncol(iris))
14+
iris
15+
```

examples/test-results-hide.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
`results = 'hide'` should try to collapse output, e.g., merge the source blocks below:
2+
3+
``` {.r}
4+
nrow(iris)
5+
ncol(iris)
6+
iris
7+
```
8+
9+
Other types of output (such as messages) will interrupt the collapsed block:
10+
11+
``` {.r}
12+
nrow(iris)
13+
message(ncol(iris))
14+
```
15+
16+
``` {.plain .message}
17+
#> 5
18+
```
19+
20+
``` {.r}
21+
iris
22+
```

0 commit comments

Comments
 (0)