| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/fuse.R |
| 3 |
\name{reactor} |
| 4 |
\alias{reactor} |
| 5 |
\title{Get and set chunk options} |
| 6 |
\usage{ |
| 7 |
reactor(...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{...}{Named values (for setting) or unnamed values (for getting).} |
| 11 |
} |
| 12 |
\value{ |
| 13 |
With no arguments, \code{reactor()} returns an environment that stores the |
| 14 |
options, which can also be used to get or set options. For example, with |
| 15 |
\code{opts = reactor()}, \code{opts$name} returns an option value, and \code{opts$name = value} sets an option to a value. |
| 16 |
|
| 17 |
With named arguments, \code{reactor()} sets options and returns a list of their |
| 18 |
old values (e.g., \code{reactor(echo = FALSE, fig.width = 8)}). The returned |
| 19 |
list can be passed to \code{reactor()} later to restore the options. |
| 20 |
|
| 21 |
With unnamed arguments, \code{reactor()} returns option values after received |
| 22 |
option names as input. If one name is received, its value is returned |
| 23 |
(e.g., \code{reactor('echo')}). If multiple names are received, a named list of |
| 24 |
values is returned (e.g., \code{reactor(c('echo', 'fig.width'))}). A special |
| 25 |
case is that if only one unnamed argument is received and it takes a list |
| 26 |
of named values, the list will be used to set options, e.g., |
| 27 |
\code{reactor(list(echo = FALSE, fig.width = 8))}, which is equivalent to |
| 28 |
\code{reactor(echo = FALSE, fig.width = 8)}. |
| 29 |
} |
| 30 |
\description{ |
| 31 |
Chunk options are stored in an environment returned by \code{reactor()}. Option |
| 32 |
values can be queried by passing their names to \code{reactor()}, and set by |
| 33 |
passing named values. |
| 34 |
} |
| 35 |
\examples{ |
| 36 |
# get options |
| 37 |
litedown::reactor("echo") |
| 38 |
litedown::reactor(c("echo", "fig.width")) |
| 39 |
|
| 40 |
# set options |
| 41 |
old = litedown::reactor(echo = FALSE, fig.width = 8) |
| 42 |
litedown::reactor(c("echo", "fig.width")) |
| 43 |
litedown::reactor(old) # restore options |
| 44 |
|
| 45 |
# use the environment directly |
| 46 |
opts = litedown::reactor() |
| 47 |
opts$echo |
| 48 |
mget(c("echo", "fig.width"), opts) |
| 49 |
ls(opts) # built-in options |
| 50 |
} |