| 1 |
.onLoad <- function(libname, pkgname) { |
| 2 |
## pander settings |
| 3 |
options('pander' = list( |
| 4 |
'digits' = 4, |
| 5 |
'decimal.mark' = '.', |
| 6 |
'formula.caption.prefix' = 'Formula: ', |
| 7 |
'big.mark' = '', |
| 8 |
'round' = Inf, |
| 9 |
'keep.trailing.zeros' = FALSE, |
| 10 |
'keep.line.breaks' = FALSE, |
| 11 |
'missing' = NA, |
| 12 |
'date' = '%Y/%m/%d %X', |
| 13 |
'header.style' = 'atx', |
| 14 |
'list.style' = 'bullet', |
| 15 |
'table.style' = ifelse( |
| 16 |
getOption('jupyter.in_kernel', FALSE), |
| 17 |
## The jupyter notebook does not understand the multiline table format |
| 18 |
'rmarkdown', |
| 19 |
'multiline'), |
| 20 |
'table.emphasize.rownames' = TRUE, |
| 21 |
'table.split.table' = 80, |
| 22 |
'table.split.cells' = 30, |
| 23 |
'table.caption.prefix' = 'Table: ', |
| 24 |
'table.continues' = 'Table continues below', |
| 25 |
'table.continues.affix' = '(continued below)', |
| 26 |
'table.alignment.default' = 'centre', |
| 27 |
'table.alignment.rownames' = 'centre', |
| 28 |
'use.hyphening' = FALSE, |
| 29 |
'evals.messages' = TRUE, |
| 30 |
'p.wrap' = '_', |
| 31 |
'p.sep' = ', ', |
| 32 |
'p.copula' = ' and ', |
| 33 |
'plain.ascii' = FALSE, |
| 34 |
'graph.nomargin' = TRUE, |
| 35 |
'graph.fontfamily' = 'sans', |
| 36 |
'graph.fontcolor' = 'black', |
| 37 |
'graph.fontsize' = 12, |
| 38 |
'graph.grid' = TRUE, |
| 39 |
'graph.grid.minor' = TRUE, |
| 40 |
'graph.grid.color' = 'grey', |
| 41 |
'graph.grid.lty' = 'dashed', |
| 42 |
'graph.boxes' = FALSE, |
| 43 |
'graph.legend.position' = 'right', |
| 44 |
'graph.background' = 'white', |
| 45 |
'graph.panel.background' = 'transparent', |
| 46 |
'graph.colors' = c("#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#999999", "#E69F00"), #nolint |
| 47 |
'graph.color.rnd' = FALSE, |
| 48 |
'graph.axis.angle' = 1, |
| 49 |
'graph.symbol' = 1, |
| 50 |
'knitr.auto.asis' = TRUE, |
| 51 |
'pandoc.binary' = path_to_pandoc() |
| 52 |
)) |
| 53 |
|
| 54 |
## evals options |
| 55 |
options('evals' = list( |
| 56 |
'parse' = TRUE, |
| 57 |
'cache' = TRUE, |
| 58 |
'cache.mode' = 'environment', |
| 59 |
'cache.dir' = '.cache', |
| 60 |
'cache.time' = 0.1, |
| 61 |
'cache.copy.images' = FALSE, |
| 62 |
'classes' = NULL, |
| 63 |
'hooks' = NULL, |
| 64 |
'length' = Inf, |
| 65 |
'output' = 'all', |
| 66 |
'graph.unify' = FALSE, |
| 67 |
'graph.name' = '%t', |
| 68 |
'graph.dir' = 'plots', |
| 69 |
'graph.output' = 'png', |
| 70 |
'width' = 480, |
| 71 |
'height' = 480, |
| 72 |
'res' = 72, |
| 73 |
'hi.res' = FALSE, |
| 74 |
'hi.res.width' = 960, |
| 75 |
'graph.env' = FALSE, |
| 76 |
'graph.recordplot' = FALSE, |
| 77 |
'graph.RDS' = FALSE, |
| 78 |
'log' = NULL |
| 79 |
)) |
| 80 |
} |
| 81 |
|
| 82 |
## general (temporary) storage for pander's stuff |
| 83 |
storage <- new.env() |
| 84 |
storage$caption <- NULL |
| 85 |
storage$alignment <- NULL |
| 86 |
debug <- new.env() |
| 87 |
debug$nested <- 0 |
| 88 |
debug$nestedID <- 0 |
| 89 |
|
| 90 |
## cache storage |
| 91 |
cached.results <- new.env() # cache of results from evals |
| 92 |
cached.environments <- new.env() # cache of changes to the environment (assignments in particular) |
| 93 |
|
| 94 |
## cache hash storage |
| 95 |
hash.cache.obj <- new.env() # raw R objects of which hash was computed before |
| 96 |
hash.cache.hash <- new.env() # the computed hash of the above R objects |
| 97 |
hash.cache.last.used <- new.env() # when was the hash last queried |
| 98 |
|
| 99 |
## masked plots |
| 100 |
masked.plots <- new.env() |
| 101 |
masked.plots$plot <- masked.plots$barplot <- masked.plots$lines <- masked.plots$pie <- masked.plots$boxplot <- masked.plots$polygon <- masked.plots$points <- masked.plots$legend <- masked.plots$hist <- masked.plots$pairs <- masked.plots$stripchart <- masked.plots$clusplot <- masked.plots$text <- function (...) { #nolint |
| 102 |
|
| 103 |
mc <- match.call() |
| 104 |
fn <- deparse(mc[[1]]) |
| 105 |
fn.pkg <- gsub('.*library/|/help.*', '', help(fn)[1]) |
| 106 |
fn.orig <- parse(text = paste0(fn.pkg, '::', fn))[[1]] |
| 107 |
mc <- match.call(get(fn, envir = .GlobalEnv)) |
| 108 |
|
| 109 |
if (!(!is.null(mc$plot) && !mc$plot)) { |
| 110 |
|
| 111 |
## pander options |
| 112 |
fc <- panderOptions('graph.fontcolor') |
| 113 |
fbs <- panderOptions('graph.fontsize') |
| 114 |
bc <- panderOptions('graph.background') |
| 115 |
gc <- panderOptions('graph.grid.color') |
| 116 |
cex <- fbs / 12 |
| 117 |
cs <- panderOptions('graph.colors') |
| 118 |
if (panderOptions('graph.color.rnd')) |
| 119 |
cs <- sample(cs) |
| 120 |
cb <- cs[1] |
| 121 |
|
| 122 |
## global par update |
| 123 |
if (!fn %in% c('text')) { |
| 124 |
par( |
| 125 |
family = panderOptions('graph.fontfamily'), |
| 126 |
cex = cex, cex.axis = cex * 0.8, cex.lab = cex, cex.main = cex * 1.2, cex.sub = cex, |
| 127 |
bg = bc, # nolint TODO: how could we color only the inner plot area globally? Not like: https://stat.ethz.ch/pipermail/r-help/2003-May/033971.html |
| 128 |
las = panderOptions('graph.axis.angle'), |
| 129 |
lwd = 2, |
| 130 |
pch = panderOptions('graph.symbol'), |
| 131 |
col.axis = fc, col.lab = fc, col.main = fc, col.sub = fc) |
| 132 |
} |
| 133 |
|
| 134 |
## remove margins |
| 135 |
|
| 136 |
if (panderOptions('graph.nomargin') & !fn %in% c('text')) { |
| 137 |
par(mar = c(4.1, 4.3, 2.1, 0.1)) |
| 138 |
} |
| 139 |
|
| 140 |
## default: grid is added to all plots |
| 141 |
doAddGrid <- TRUE |
| 142 |
|
| 143 |
## update colors |
| 144 |
if (is.null(mc$col) & is.null(mc$color)) |
| 145 |
mc$col <- cb |
| 146 |
if (fn == 'boxplot') |
| 147 |
mc$border <- 'black' |
| 148 |
if (fn == 'clusplot') { |
| 149 |
mc$col <- NULL |
| 150 |
if (is.null(mc$color)) |
| 151 |
mc$color <- TRUE |
| 152 |
if (is.null(mc$shade)) |
| 153 |
mc$shade <- TRUE |
| 154 |
if (is.null(mc$labels)) |
| 155 |
mc$labels <- 4 |
| 156 |
if (is.null(mc$col.p)) |
| 157 |
mc$col.p <- 'black' |
| 158 |
if (is.null(mc$col.clus)) |
| 159 |
mc$col.clus <- cs |
| 160 |
} |
| 161 |
|
| 162 |
## remove boxes |
| 163 |
if (fn %in% c('pairs', 'stripchart')) { |
| 164 |
doAddGrid <- FALSE |
| 165 |
par(fg = fc) |
| 166 |
} else { |
| 167 |
if (panderOptions('graph.boxes')) |
| 168 |
par(fg = gc) |
| 169 |
else |
| 170 |
par(fg = bc) |
| 171 |
} |
| 172 |
|
| 173 |
if (fn == 'pie') |
| 174 |
mc$col <- cs |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
## call |
| 179 |
mc[[1]] <- fn.orig |
| 180 |
eval(mc, envir = parent.frame()) |
| 181 |
|
| 182 |
## grid |
| 183 |
if (all(par()$mfrow == 1) & panderOptions('graph.grid') & doAddGrid & !(!is.null(mc$plot) && !mc$plot)) { |
| 184 |
|
| 185 |
g <- tryCatch(grid(lty = panderOptions('graph.grid.lty'), |
| 186 |
col = panderOptions('graph.grid.color'), |
| 187 |
lwd = 0.5), |
| 188 |
error = function(e) e) |
| 189 |
if (!inherits(g, 'error')) { |
| 190 |
if (panderOptions('graph.grid.minor')) |
| 191 |
g <- tryCatch(add.minor.ticks(2, 2, grid = TRUE), error = function(e) e) |
| 192 |
} |
| 193 |
if (inherits(g, 'error')) |
| 194 |
warning('Applying default formatting to image is somehow compromised (the result could differ from what you specified in `panderOptions`). Hints: printing `lattice`/`ggplot2` is not needed and tweaking `base` plots with `par` might have some side-effects!') #nolint |
| 195 |
|
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
#' Querying/setting pander option |
| 201 |
#' |
| 202 |
#' To list all \code{pander} options, just run this function without any parameters provided. To query only one value, pass the first parameter. To set that, use the \code{value} parameter too. |
| 203 |
#' |
| 204 |
#' The following \code{pander} options are available: |
| 205 |
#' |
| 206 |
#' \itemize{ |
| 207 |
#' \item \code{digits}: numeric (default: \code{2}) passed to \code{format}. Can be a vector specifying values for each column (has to be the same length as number of columns). Values for non-numeric columns will be disregarded. |
| 208 |
#' \item \code{decimal.mark}: string (default: \code{.}) passed to \code{format} |
| 209 |
#' \item \code{formula.caption.prefix}: string (default: \code{'Formula: '}) passed to \code{\link{pandoc.formula}} to be used as caption prefix. Be sure about what you are doing if changing to other than \code{'Formula: '} or \code{':'}. |
| 210 |
#' \item \code{big.mark}: string (default: '') passed to \code{format}. |
| 211 |
#' \item \code{round}: numeric (default: \code{Inf}) passed to \code{round}. Can be a vector specifying values for each column (has to be the same length as number of columns). Values for non-numeric columns will be disregarded. |
| 212 |
#' \item \code{keep.trailing.zeros}: boolean (default: \code{FALSE}) to show or remove trailing zeros in numbers |
| 213 |
#' \item \code{keep.line.breaks}: boolean (default: \code{FALSE}) to keep or remove line breaks from cells in a table |
| 214 |
#' \item \code{missing}: string (default: \code{NA}) to replace missing values in vectors, tables etc. |
| 215 |
#' \item \code{date}: string (default: \code{'\%Y/\%m/\%d \%X'}) passed to \code{format} when printing dates (\code{POSIXct} or \code{POSIXt}) |
| 216 |
#' \item \code{header.style}: \code{'atx'} or \code{'setext'} passed to \code{\link{pandoc.header}} |
| 217 |
#' \item \code{list.style}: \code{'bullet'}, \code{'ordered'} or \code{'roman'} passed to \code{\link{pandoc.list}}. Please not that this has no effect on \code{pander} methods. |
| 218 |
#' \item \code{table.style}: \code{'multiline'}, \code{'grid'}, \code{'simple'} or \code{'rmarkdown'} passed to \code{\link{pandoc.table}} |
| 219 |
#' \item \code{table.emphasize.rownames}: boolean (default: \code{TRUE}) if row names should be highlighted |
| 220 |
#' \item \code{table.split.table}: numeric passed to \code{\link{pandoc.table}} and also affects \code{pander} methods. This option tells \code{pander} where to split too wide tables. The default value (\code{80}) suggests the conventional number of characters used in a line, feel free to change (e.g. to \code{Inf} to disable this feature) if you are not using a VT100 terminal any more :) |
| 221 |
#' \item \code{table.split.cells}: numeric or numeric vector (default: \code{30}) passed to \code{\link{pandoc.table}} and also affects \code{pander} methods. This option tells \code{pander} where to split too wide cells with line breaks. Numeric vector specifies values for cells separately. Set \code{Inf} to disable. |
| 222 |
#' \item \code{table.caption.prefix}: string (default: \code{'Table: '}) passed to \code{\link{pandoc.table}} to be used as caption prefix. Be sure about what you are doing if changing to other than \code{'Table: '} or \code{':'}. |
| 223 |
#' \item \code{table.continues}: string (default: \code{'Table continues below'}) passed to \code{\link{pandoc.table}} to be used as caption for long (split) without a use defined caption |
| 224 |
#' \item \code{table.continues.affix}: string (default: \code{'(continued below)'}) passed to \code{\link{pandoc.table}} to be used as an affix concatenated to the user defined caption for long (split) tables |
| 225 |
#' \item \code{table.alignment.default}: string (default: \code{centre}) that defines the default alignment of cells. Can be \code{left}, \code{right} or \code{centre} that latter can be also spelled as \code{center}. |
| 226 |
#' \item \code{table.alignment.rownames}: string (default: \code{centre}) that defines the alignment of rownames in tables. Can be \code{left}, \code{right} or \code{centre} that latter can be also spelled as \code{center}. |
| 227 |
#' \item \code{use.hyphening}: boolean (default: \code{FALSE}) if try to use hyphening when splitting large cells according to table.split.cells. Requires \pkg{sylly}. |
| 228 |
#' \item \code{evals.messages}: boolean (default: \code{TRUE}) passed to \code{evals}' \code{pander} method specifying if messages should be rendered |
| 229 |
#' \item \code{p.wrap}: a string (default: \code{'_'}) to wrap vector elements passed to \code{p} function |
| 230 |
#' \item \code{p.sep}: a string (default: \code{', '}) with the main separator passed to \code{p} function |
| 231 |
#' \item \code{p.copula}: a string (default: \code{' and '}) with ending separator passed to \code{p} function |
| 232 |
#' \item \code{plain.ascii}: boolean (default: \code{FALSE}) to define if output should be in plain ascii or not |
| 233 |
#' \item \code{graph.nomargin}: boolean (default: \code{TRUE}) if trying to keep plots' margins at minimal |
| 234 |
#' \item \code{graph.fontfamily}: string (default: \code{'sans'}) specifying the font family to be used in images. Please note, that using a custom font on Windows requires \code{grDevices:::windowsFonts} first. |
| 235 |
#' \item \code{graph.fontcolor}: string (default: \code{'black'}) specifying the default font color |
| 236 |
#' \item \code{graph.fontsize}: numeric (default: \code{12}) specifying the \emph{base} font size in pixels. Main title is rendered with \code{1.2} and labels with \code{0.8} multiplier. |
| 237 |
#' \item \code{graph.grid}: boolean (default: \code{TRUE}) if a grid should be added to the plot |
| 238 |
#' \item \code{graph.grid.minor}: boolean (default: \code{TRUE}) if a miner grid should be also rendered |
| 239 |
#' \item \code{graph.grid.color}: string (default: \code{'grey'}) specifying the color of the rendered grid |
| 240 |
#' \item \code{graph.grid.lty}: string (default: \code{'dashed'}) specifying the line type of grid |
| 241 |
#' \item \code{graph.boxes}: boolean (default: \code{FALSE}) if to render a border around of plot (and e.g. around strip) |
| 242 |
#' \item \code{graph.legend.position}: string (default: \code{'right'}) specifying the position of the legend: 'top', 'right', 'bottom' or 'left' |
| 243 |
#' \item \code{graph.background}: string (default: \code{'white'}) specifying the plots main background's color |
| 244 |
#' \item \code{graph.panel.background}: string (default: \code{'transparent'}) specifying the plot's main panel background. Please \emph{note}, that this option is not supported with \code{base} graphics. |
| 245 |
#' \item \code{graph.colors}: character vector of default color palette (defaults to a colorblind theme: \url{https://jfly.uni-koeln.de/color/}). Please \emph{note} that this update work with \code{base} plots by appending the \code{col} argument to the call if not set. |
| 246 |
#' \item \code{graph.color.rnd}: boolean (default: \code{FALSE}) specifying if the palette should be reordered randomly before rendering each plot to get colorful images |
| 247 |
#' \item \code{graph.axis.angle}: numeric (default: \code{1}) specifying the angle of axes' labels. The available options are based on \code{par(les)} and sets if the labels should be: |
| 248 |
#' \itemize{ |
| 249 |
#' \item \code{1}: parallel to the axis, |
| 250 |
#' \item \code{2}: horizontal, |
| 251 |
#' \item \code{3}: perpendicular to the axis or |
| 252 |
#' \item \code{4}: vertical. |
| 253 |
#' } |
| 254 |
#' \item \code{graph.symbol}: numeric (default: \code{1}) specifying a symbol (see the \code{pch} parameter of \code{par}) |
| 255 |
#' \item \code{knitr.auto.asis}: boolean (default: \code{TRUE}) if the results of \code{pander} should be considered as \code{'asis'} in \code{knitr}. Equals to specifying \code{results='asis'} in the R chunk, so thus there is no need to do so if set to \code{TRUE}. |
| 256 |
#' \item \code{pandoc.binary}: full path of \code{pandoc}'s binary. By default, \code{pandoc} is in the path. |
| 257 |
#' } |
| 258 |
#' @param o option name (string). See below. |
| 259 |
#' @param value value to assign (optional) |
| 260 |
#' @export |
| 261 |
#' @seealso \code{\link{evalsOptions}} |
| 262 |
#' @examples \dontrun{ |
| 263 |
#' panderOptions() |
| 264 |
#' panderOptions('digits') |
| 265 |
#' panderOptions('digits', 5) |
| 266 |
#' } |
| 267 |
panderOptions <- function(o, value) { |
| 268 |
|
| 269 |
res <- getOption('pander') |
| 270 |
|
| 271 |
## just querying |
| 272 |
if (missing(value)) { |
| 273 |
|
| 274 |
if (missing(o)) |
| 275 |
return(res) |
| 276 |
|
| 277 |
if (o %in% names(res)) |
| 278 |
return(res[[o]]) |
| 279 |
|
| 280 |
pandoc.header('Possible `pander` options:', style = 'setext') |
| 281 |
pandoc.list(names(res)) |
| 282 |
stop('Wrong option queried.') |
| 283 |
|
| 284 |
} else { |
| 285 |
|
| 286 |
if (!o %in% names(res)) |
| 287 |
stop(paste('Invalid option name:', o)) |
| 288 |
|
| 289 |
## fix assigning NULL to a list element |
| 290 |
if (is.null(value)) { |
| 291 |
res[o] <- list(NULL) |
| 292 |
} else { |
| 293 |
res[[o]] <- value |
| 294 |
} |
| 295 |
|
| 296 |
options('pander' = res) |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
#' Querying/setting evals option |
| 304 |
#' |
| 305 |
#' To list all \code{evals} options, just run this function without any parameters provided. To query only one value, pass the first parameter. To set that, use the \code{value} parameter too. |
| 306 |
#' |
| 307 |
#' The following \code{evals} options are available: |
| 308 |
#' |
| 309 |
#' \itemize{ |
| 310 |
#' \item \code{parse}: if \code{TRUE} the provided \code{txt} elements would be merged into one string and parsed to logical chunks. This is useful if you would want to get separate results of your code parts - not just the last returned value, but you are passing the whole script in one string. To manually lock lines to each other (e.g. calling a \code{plot} and on next line adding an \code{abline} or \code{text} to it), use a plus char (\code{+}) at the beginning of each line which should be evaluated with the previous one(s). If set to \code{FALSE}, \code{evals} would not try to parse R code, it would get evaluated in separate runs - as provided. Please see examples of \code{\link{evals}}. |
| 311 |
#' \item \code{cache}: caching the result of R calls if set to \code{TRUE} |
| 312 |
#' \item \code{cache.mode}: cached results could be stored in an \code{environment} in \emph{current} R session or let it be permanent on \code{disk}. |
| 313 |
#' \item \code{cache.dir}: path to a directory holding cache files if \code{cache.mode} set to \code{disk}. Default to \code{.cache} in current working directory. |
| 314 |
#' \item \code{cache.time}: number of seconds to limit caching based on \code{proc.time}. If set to \code{0}, all R commands, if set to \code{Inf}, none is cached (despite the \code{cache} parameter). |
| 315 |
#' \item \code{cache.copy.images}: copy images to new files if an image is returned from cache? If set to \code{FALSE} (default) the "old" path would be returned. |
| 316 |
#' \item \code{classes}: a vector or list of classes which should be returned. If set to \code{NULL} (by default) all R objects will be returned. |
| 317 |
#' \item \code{hooks}: list of hooks to be run for given classes in the form of \code{list(class = fn)}. If you would also specify some parameters of the function, a list should be provided in the form of \code{list(fn, param1, param2=NULL)} etc. So the hooks would become \code{list(class1=list(fn, param1, param2=NULL), ...)}. See examples of \code{\link{evals}}. A default hook can be specified too by setting the class to \code{'default'}. This can be handy if you do not want to define separate methods/functions to each possible class, but automatically apply the default hook to all classes not mentioned in the list. You may also specify only one element in the list like: \code{hooks=list('default' = pander_return)}. Please note, that nor error/warning messages, nor stdout is captured (so: updated) while running hooks! |
| 318 |
#' \item \code{length}: any R object exceeding the specified length will not be returned. The default value (\code{Inf}) does not filter out any R objects. |
| 319 |
#' \item \code{output}: a character vector of required returned values. This might be useful if you are only interested in the \code{result}, and do not want to save/see e.g. \code{messages} or \code{print}ed \code{output}. See examples of \code{\link{evals}}. |
| 320 |
#' \item \code{graph.unify}: boolean (default: \code{FALSE}) that determines if \code{evals} should try to unify the style of (\code{base}, \code{lattice} and \code{ggplot2}) plots? If set to \code{TRUE}, some \code{panderOptions()} would apply. |
| 321 |
#' \item \code{graph.name}: set the file name of saved plots which is \code{\link{tempfile}} by default. A simple character string might be provided where \code{\%d} would be replaced by the index of the generating \code{txt} source, \code{\%n} with an incremented integer in \code{graph.dir} with similar file names and \code{\%t} by some random characters. A function's name to be \code{eval}uated can be passed here too. |
| 322 |
#' \item \code{graph.dir}: path to a directory where to place generated images. If the directory does not exist, \code{\link{evals}} try to create that. Default set to \code{plots} in current working directory. |
| 323 |
#' \item \code{graph.output}: set the required file format of saved plots. Currently it could be any of \code{grDevices}: \code{png}, \code{bmp}, \code{jpeg}, \code{jpg}, \code{tiff}, \code{svg} or \code{pdf}. Set to \code{NA} not to save plots at all and tweak that setting with \code{capture.plot()} on demand. |
| 324 |
#' \item \code{width}: width of generated plot in pixels for even vector formats |
| 325 |
#' \item \code{height}: height of generated plot in pixels for even vector formats |
| 326 |
#' \item \code{res}: nominal resolution in \code{ppi}. The height and width of vector images will be calculated based in this. |
| 327 |
#' \item \code{hi.res}: generate high resolution plots also? If set to \code{TRUE}, each R code parts resulting an image would be run twice. |
| 328 |
#' \item \code{hi.res.width}: width of generated high resolution plot in pixels for even vector formats. The \code{height} and \code{res} of high resolution image is automatically computed based on the above options to preserve original plot aspect ratio. |
| 329 |
#' \item \code{graph.env}: save the environments in which plots were generated to distinct files (based on \code{graph.name}) with \code{env} extension? |
| 330 |
#' \item \code{graph.recordplot}: save the plot via \code{recordPlot} to distinct files (based on \code{graph.name}) with \code{recodplot} extension? |
| 331 |
#' \item \code{graph.RDS}: save the raw R object returned (usually with \code{lattice} or \code{ggplot2}) while generating the plots to distinct files (based on \code{graph.name}) with \code{RDS} extension? |
| 332 |
#' \item \code{log}: \code{NULL} or an optionally passed \emph{namespace} from \pkg{logger} to record all info, trace, debug and error messages. |
| 333 |
#' } |
| 334 |
#' @param o option name (string). See below. |
| 335 |
#' @param value value to assign (optional) |
| 336 |
#' @export |
| 337 |
#' @seealso \code{\link{evals}} \code{\link{panderOptions}} |
| 338 |
#' @examples |
| 339 |
#' evalsOptions() |
| 340 |
#' evalsOptions('cache') |
| 341 |
#' evalsOptions('cache', FALSE) |
| 342 |
evalsOptions <- function(o, value) { |
| 343 |
|
| 344 |
res <- getOption('evals') |
| 345 |
|
| 346 |
## just querying |
| 347 |
if (missing(value)) { |
| 348 |
|
| 349 |
if (missing(o)) |
| 350 |
return(res) |
| 351 |
|
| 352 |
if (o %in% names(res)) |
| 353 |
return(res[[o]]) |
| 354 |
|
| 355 |
pandoc.header('Possible `evals` options:', style = 'setext') |
| 356 |
pandoc.list(names(res)) |
| 357 |
stop('Wrong option queried.') |
| 358 |
|
| 359 |
} else { |
| 360 |
|
| 361 |
if (!o %in% names(res)) |
| 362 |
stop(paste('Invalid option name:', o)) |
| 363 |
|
| 364 |
## fix assigning NULL to a list element |
| 365 |
if (is.null(value)) { |
| 366 |
res[o] <- list(NULL) |
| 367 |
} else { |
| 368 |
res[[o]] <- value |
| 369 |
} |
| 370 |
|
| 371 |
options('evals' = res) |
| 372 |
|
| 373 |
} |
| 374 |
|
| 375 |
} |