| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/knitr.R |
| 3 |
\name{divide_chunk} |
| 4 |
\alias{divide_chunk} |
| 5 |
\title{Divide chunk options from the code chunk body} |
| 6 |
\usage{ |
| 7 |
divide_chunk(engine, code, strict = FALSE, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{engine}{The name of the language engine (to determine the appropriate |
| 11 |
comment character).} |
| 12 |
|
| 13 |
\item{code}{A character vector (lines of code).} |
| 14 |
|
| 15 |
\item{strict}{If \code{FALSE}, allow chunk options to be written after \verb{#|} even |
| 16 |
if \verb{#} is not the comment character of the engine (e.g., when \code{engine = 'js'}), otherwise throw an error if \verb{#|} is detected but \verb{#} is not the |
| 17 |
comment character.} |
| 18 |
|
| 19 |
\item{...}{Arguments to be passed to \code{\link[=yaml_load]{yaml_load()}}.} |
| 20 |
} |
| 21 |
\value{ |
| 22 |
A list with the following items: |
| 23 |
\itemize{ |
| 24 |
\item \code{options}: The parsed options (if there are any) as a list. |
| 25 |
\item \code{src}: The part of the input that contains the options. |
| 26 |
\item \code{code}: The part of the input that contains the code. |
| 27 |
} |
| 28 |
} |
| 29 |
\description{ |
| 30 |
Chunk options can be written in special comments (e.g., after \verb{#|} for R code |
| 31 |
chunks) inside a code chunk. This function partitions these options from the |
| 32 |
chunk body. |
| 33 |
} |
| 34 |
\note{ |
| 35 |
Chunk options must be written on \emph{continuous} lines (i.e., all lines |
| 36 |
must start with the special comment prefix such as \verb{#|}) at the beginning |
| 37 |
of the chunk body. |
| 38 |
} |
| 39 |
\examples{ |
| 40 |
# parse yaml-like items |
| 41 |
yaml_like = c("#| label: mine", "#| echo: true", "#| fig.width: 8", "#| foo: bar", |
| 42 |
"1 + 1") |
| 43 |
writeLines(yaml_like) |
| 44 |
xfun::divide_chunk("r", yaml_like) |
| 45 |
|
| 46 |
# parse CSV syntax |
| 47 |
csv_like = c("#| mine, echo = TRUE, fig.width = 8, foo = 'bar'", "1 + 1") |
| 48 |
writeLines(csv_like) |
| 49 |
xfun::divide_chunk("r", csv_like) |
| 50 |
} |