Skip to content

Commit

Permalink
close #2268: preserve #| chunk options in purl() output
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Aug 24, 2023
1 parent da38cf7 commit 66d7700
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
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.43.5
Version: 1.43.6
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
Expand Up @@ -14,6 +14,10 @@

- Use the correct type of progress bar when rendering Quarto documents in RStudio, which takes place in RStudio's background jobs pane (thanks, @hadley, #2271).

## MINOR CHANGES

- In-body chunk options (`#|`) are now preserved when extracting code from a document via `purl()` (thanks, @LuisLauM, #2268).

# CHANGES IN knitr VERSION 1.43

## NEW FEATURES
Expand Down
5 changes: 2 additions & 3 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,12 @@ process_tangle.inline = function(x) {

# add a label [and extra chunk options] to a code chunk
label_code = function(code, options) {
code = one_string(c('', code, ''))
comments = if (is_quarto()) one_string(options$params$yaml.code) else paste0(
comments = paste0(
'## ----', options$params.src,
strrep('-', max(getOption('width') - 11L - nchar(options$params.src), 0L)),
'----'
)
paste0(comments, code)
one_string(c(comments, options$params.chunk, code, ''))
}

as.source = function(code) {
Expand Down
4 changes: 3 additions & 1 deletion R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ parse_block = function(code, header, params.src, markdown_mode = out_format('mar
}
}

structure(list(params = params, params.src = params.src), class = 'block')
structure(class = 'block', list(
params = params, params.src = params.src, params.chunk = parts$src)
)
}

get_chunk_indent = function(header) {
Expand Down
9 changes: 2 additions & 7 deletions tests/testit/test-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ assert('inline_exec only accept character result', {
assert('label_code correct adds comment on code for yaml block or parsed param', {
oldW = getOption('width')
options(width = 20)
old = .knitEnv$is_quarto
.knitEnv$is_quarto = FALSE
(label_code("1+1", list(params.src = "test, eval=TRUE")) %==% "## ----test, eval=TRUE----\n1+1\n")
options(width = oldW)
.knitEnv$is_quarto = TRUE
(label_code("1+1",
list(params = list(yaml.code = c("#| label: test", "#| eval: true")))
) %==% "#| label: test\n#| eval: true\n1+1\n")
.knitEnv$is_quarto = NULL
(label_code("1+1", list(params.chunk = c("#| label: test", "#| eval: true"))) %==%
"## --------\n#| label: test\n#| eval: true\n1+1\n")
})

0 comments on commit 66d7700

Please sign in to comment.