forked from yihui/knitr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaults.R
98 lines (90 loc) · 3.64 KB
/
defaults.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
new_defaults = function(value = list()) {
defaults = value
get = function(name, default = FALSE) {
if (default) defaults = value # this is only a local version
if (missing(name)) defaults else {
if (length(name) == 1) defaults[[name]] else defaults[name]
}
}
set = function(...) {
dots = list(...)
if (length(dots) == 0) return()
if (length(dots) == 1 && is.list(dots[[1]]))
dots = dots[[1]]
defaults <<- merge(dots)
invisible(NULL)
}
merge = function(values) {
defaults[names(values)] = values
defaults
}
restore = function() defaults <<- value
list(get = get, set = set, merge = merge, restore = restore)
}
#' Default and current chunk options
#'
#' Options for R code chunks. When running R code, the object \code{opts_chunk}
#' (default options) is not modified by chunks (local chunk options are merged
#' with default options), whereas \code{opts_current} (current options) changes
#' with different chunks.
#' @references Usage: \url{http://yihui.name/knitr/objects}
#'
#' A list of available options:
#' \url{http://yihui.name/knitr/options#chunk_options}
#' @export
#' @examples opts_chunk$get('prompt'); opts_chunk$get('fig.keep')
opts_chunk = new_defaults(
list(eval = TRUE, echo = TRUE, results = 'markup', tidy = TRUE,
cache = FALSE, dependson = NULL, cache.path = 'cache/',
ref.label = NULL, child = NULL, engine = 'R',
prompt = FALSE, comment = '##', autodep = FALSE,
fig.keep = 'high', fig.show = 'asis', fig.align = 'default',
fig.path = 'figure/', fig.ext = NULL, dev = 'pdf', dpi = 72,
dev.args = NULL, fig.width = 7, fig.height = 7,
fig.cap = NULL, fig.scap = NULL, fig.lp = 'fig:', fig.pos = '',
out.width = NULL, out.height = NULL,
resize.width = NULL, resize.height = NULL,
external = TRUE, sanitize = FALSE,
highlight = TRUE, size = 'normalsize',
warning = TRUE, error = TRUE, message = TRUE,
background = '#F7F7F7', split = FALSE, include = TRUE,
interval = 1, aniopts = 'controls,loop')
)
#' @rdname opts_chunk
#' @export
opts_current = new_defaults()
## a list of options attributes for RStudio
opts_chunk_attr = (function() {
opts = lapply(opts_chunk$get(), class)
opts[opts == 'NULL'] = 'character'
opts$results = list('markup', 'asis', 'hide')
opts$fig.show = list('asis', 'hold', 'animate')
opts$fig.keep = list('high', 'none', 'all', 'first', 'last')
opts$fig.align = list('default', 'left', 'right', 'center')
opts$dev = as.list(names(auto_exts))
opts$fig.ext = as.list(unique(auto_exts))
opts
})()
#' Options for the knitr package
#'
#' Options including whether to use a progress bar when knitting a document, and
#' the base directory of images, etc.
#' @references Usage: \url{http://yihui.name/knitr/objects}
#'
#' A list of available options:
#' \url{http://yihui.name/knitr/options#package_options}
#' @export
#' @examples opts_knit$get('verbose'); opts_knit$set(verbose = TRUE) # change it
opts_knit = new_defaults(
list(progress = TRUE, verbose = FALSE, out.format = NULL,
child.command = 'input', base.dir = NULL, base.url = NULL, child.path = '',
upload.fun = identity, eval.after = NULL, concordance = FALSE,
tangle = FALSE, child = FALSE, parent = FALSE,
cache.extra = NULL, aliases = NULL, root.dir = NULL,
self.contained = TRUE, filter.chunk.end = TRUE,
header = c(highlight = '', tikz = '', framed = ''))
)
## header should not be set by hand unless you know what you are doing
## tangle: whether I'm in tangle mode; child: whether I'm in child
## document mode; parent: whether I need to add parent preamble to the
## child output