
Last chance! 50% off unlimited learning
Sale ends in
Chunk options can be written in special comments (e.g., after #|
for R code
chunks) inside a code chunk. This function partitions these options from the
chunk body.
divide_chunk(engine, code, strict = FALSE, ...)
A list with the following items:
options
: The parsed options (if there are any) as a list.
src
: The part of the input that contains the options.
code
: The part of the input that contains the code.
The name of the language engine (to determine the appropriate comment character).
A character vector (lines of code).
If FALSE
, allow chunk options to be written after #|
even
if #
is not the comment character of the engine (e.g., when engine = 'js'
), otherwise throw an error if #|
is detected but #
is not the
comment character.
Arguments to be passed to yaml_load()
.
# parse yaml-like items
yaml_like = c("#| label: mine", "#| echo: true", "#| fig.width: 8", "#| foo: bar",
"1 + 1")
writeLines(yaml_like)
xfun::divide_chunk("r", yaml_like)
# parse CSV syntax
csv_like = c("#| mine, echo = TRUE, fig.width = 8, foo = 'bar'", "1 + 1")
writeLines(csv_like)
xfun::divide_chunk("r", csv_like)
Run the code above in your browser using DataLab