Commit d30e79cd authored by Andreas Tille's avatar Andreas Tille

New upstream version 1.20

parent de5d7451
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.17
Date: 2017-08-09
Version: 1.20
Authors@R: c(
person("Yihui", "Xie", email = "xie@yihui.name", role = c("aut", "cre")),
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Adam", "Vogt", role = "ctb"),
person("Alastair", "Andrew", role = "ctb"),
person("Alex", "Zvoleff", role = "ctb"),
......@@ -15,10 +14,13 @@ Authors@R: c(
person("Ben", "Baumer", role = "ctb"),
person("Brian", "Diggs", role = "ctb"),
person("Cassio", "Pereira", role = "ctb"),
person("Christophe", "Dervieux", role = "ctb"),
person("David", "Hugh-Jones", role = "ctb"),
person("David", "Robinson", role = "ctb"),
person("Donald", "Arseneau", role = c("ctb", "cph"), comment = "the framed package at inst/misc/framed.sty"),
person("Doug", "Hemken", role = "ctb"),
person("Duncan", "Murdoch", role = "ctb"),
person("Elio", "Campitelli", role = "ctb"),
person("Fabian", "Hirschmann", role = "ctb"),
person("Fitch", "Simeon", role = "ctb"),
person("Forest", "Fang", role = "ctb"),
......@@ -37,6 +39,7 @@ Authors@R: c(
person("Jason", "Punyon", role = "ctb"),
person("Javier", "Luraschi", role = "ctb"),
person("Jeff", "Arnold", role = "ctb"),
person("Jenny", "Bryan", role = "ctb"),
person("Jeremy", "Ashkenas", role = c("ctb", "cph"), comment = "the CSS file at inst/misc/docco-classic.css"),
person("Jeremy", "Stephens", role = "ctb"),
person("Jim", "Hester", role = "ctb"),
......@@ -47,6 +50,7 @@ Authors@R: c(
person("Jonathan", "Keane", role = "ctb"),
person("JJ", "Allaire", role = "ctb"),
person("Johan", "Toloe", role = "ctb"),
person("Jonathan", "Sidi", role = "ctb"),
person("Joseph", "Larmarange", role = "ctb"),
person("Julien", "Barnier", role = "ctb"),
person("Kaiyin", "Zhong", role = "ctb"),
......@@ -55,17 +59,21 @@ Authors@R: c(
person(c("Kevin", "K."), "Smith", role = "ctb"),
person("Kirill", "Mueller", role = "ctb"),
person("Kohske", "Takahashi", role = "ctb"),
person("Martin", "Modrák", role = "ctb"),
person("Michael", "Chirico", role = "ctb"),
person("Michael", "Friendly", role = "ctb"),
person("Michal", "Bojanowski", role = "ctb"),
person("Michel", "Kuhlmann", role = "ctb"),
person("Nacho", "Caballero", role = "ctb"),
person("Nick", "Salkowski", role = "ctb"),
person("Noam", "Ross", role = "ctb"),
person("Obada", "Mahdi", role = "ctb"),
person("Qiang", "Li", role = "ctb"),
person("Ramnath", "Vaidyanathan", role = "ctb"),
person("Richard", "Cotton", role = "ctb"),
person("Robert", "Krzyzanowski", role = "ctb"),
person("Romain", "Francois", role = "ctb"),
person("Ruaridh", "Williamson", role = "ctb"),
person("Scott", "Kostyshak", role = "ctb"),
person("Sebastian", "Meyer", role = "ctb"),
person("Sietse", "Brouwer", role = "ctb"),
......@@ -86,14 +94,16 @@ Maintainer: Yihui Xie <xie@yihui.name>
Description: Provides a general-purpose tool for dynamic report generation in R
using Literate Programming techniques.
Depends: R (>= 3.1.0)
Imports: evaluate (>= 0.10), digest, highr, markdown, stringr (>= 0.6),
yaml, methods, tools
Suggests: formatR, testit, rgl (>= 0.95.1201), codetools, rmarkdown,
htmlwidgets (>= 0.7), webshot, tikzDevice (>= 0.10), png, jpeg,
XML, RCurl, DBI (>= 0.4-1), tibble
Imports: evaluate (>= 0.10), highr, markdown, stringr (>= 0.6), yaml,
methods, tools
Suggests: formatR, testit, digest, rgl (>= 0.95.1201), codetools,
rmarkdown, htmlwidgets (>= 0.7), webshot, tikzDevice (>= 0.10),
tinytex, xfun, reticulate (>= 1.4), JuliaCall (>= 0.11.1), png,
jpeg, xml2, httr, DBI (>= 0.4-1), showtext, tibble
License: GPL
URL: https://yihui.name/knitr/
BugReports: https://github.com/yihui/knitr/issues
Encoding: UTF-8
VignetteBuilder: knitr
SystemRequirements: Package vignettes based on R Markdown v2 or
reStructuredText require Pandoc (http://pandoc.org). The
......@@ -110,8 +120,8 @@ Collate: 'block.R' 'cache.R' 'utils.R' 'citation.R' 'hooks-html.R'
'utils-vignettes.R' 'zzz.R'
RoxygenNote: 6.0.1
NeedsCompilation: no
Packaged: 2017-08-09 06:32:13 UTC; yihui
Author: Yihui Xie [aut, cre],
Packaged: 2018-02-19 20:23:59 UTC; yihui
Author: Yihui Xie [aut, cre] (<https://orcid.org/0000-0003-0645-5666>),
Adam Vogt [ctb],
Alastair Andrew [ctb],
Alex Zvoleff [ctb],
......@@ -123,10 +133,13 @@ Author: Yihui Xie [aut, cre],
Ben Baumer [ctb],
Brian Diggs [ctb],
Cassio Pereira [ctb],
Christophe Dervieux [ctb],
David Hugh-Jones [ctb],
David Robinson [ctb],
Donald Arseneau [ctb, cph] (the framed package at inst/misc/framed.sty),
Doug Hemken [ctb],
Duncan Murdoch [ctb],
Elio Campitelli [ctb],
Fabian Hirschmann [ctb],
Fitch Simeon [ctb],
Forest Fang [ctb],
......@@ -145,6 +158,7 @@ Author: Yihui Xie [aut, cre],
Jason Punyon [ctb],
Javier Luraschi [ctb],
Jeff Arnold [ctb],
Jenny Bryan [ctb],
Jeremy Ashkenas [ctb, cph] (the CSS file at
inst/misc/docco-classic.css),
Jeremy Stephens [ctb],
......@@ -156,6 +170,7 @@ Author: Yihui Xie [aut, cre],
Jonathan Keane [ctb],
JJ Allaire [ctb],
Johan Toloe [ctb],
Jonathan Sidi [ctb],
Joseph Larmarange [ctb],
Julien Barnier [ctb],
Kaiyin Zhong [ctb],
......@@ -164,17 +179,21 @@ Author: Yihui Xie [aut, cre],
Kevin K. Smith [ctb],
Kirill Mueller [ctb],
Kohske Takahashi [ctb],
Martin Modrák [ctb],
Michael Chirico [ctb],
Michael Friendly [ctb],
Michal Bojanowski [ctb],
Michel Kuhlmann [ctb],
Nacho Caballero [ctb],
Nick Salkowski [ctb],
Noam Ross [ctb],
Obada Mahdi [ctb],
Qiang Li [ctb],
Ramnath Vaidyanathan [ctb],
Richard Cotton [ctb],
Robert Krzyzanowski [ctb],
Romain Francois [ctb],
Ruaridh Williamson [ctb],
Scott Kostyshak [ctb],
Sebastian Meyer [ctb],
Sietse Brouwer [ctb],
......@@ -191,4 +210,4 @@ Author: Yihui Xie [aut, cre],
Wush Wu [ctb],
Zachary Foster [ctb]
Repository: CRAN
Date/Publication: 2017-08-10 04:27:37 UTC
Date/Publication: 2018-02-20 10:11:46 UTC
This diff is collapsed.
......@@ -56,6 +56,8 @@ export(include_app)
export(include_graphics)
export(include_url)
export(inline_expr)
export(is_html_output)
export(is_latex_output)
export(kable)
export(knit)
export(knit2html)
......
......@@ -65,7 +65,7 @@ call_block = function(block) {
if (params$engine == 'R' && isFALSE(params$cache.comments)) {
content[['code']] = parse_only(content[['code']])
}
hash = paste(valid_path(params$cache.path, label), digest::digest(content), sep = '_')
hash = paste(valid_path(params$cache.path, label), digest(content), sep = '_')
params$hash = hash
if (cache$exists(hash, params$cache.lazy) &&
isFALSE(params$cache.rebuild) &&
......@@ -104,6 +104,7 @@ block_exec = function(options) {
res.before = run_hooks(before = TRUE, options)
engine = get_engine(options$engine)
output = in_dir(input_dir(), engine(options))
if (is.list(output)) output = unlist(output)
res.after = run_hooks(before = FALSE, options)
output = paste(c(res.before, output, res.after), collapse = '')
output = knit_hooks$get('chunk')(output, options)
......@@ -421,7 +422,10 @@ call_inline = function(block) {
in_dir(input_dir(), inline_exec(block))
}
inline_exec = function(block, envir = knit_global(), hook = knit_hooks$get('inline')) {
inline_exec = function(
block, envir = knit_global(), hook = knit_hooks$get('inline'),
hook_eval = knit_hooks$get('evaluate.inline')
) {
# run inline code and substitute original texts
code = block$code; input = block$input
......@@ -429,8 +433,7 @@ inline_exec = function(block, envir = knit_global(), hook = knit_hooks$get('inli
loc = block$location
for (i in 1:n) {
v = withVisible(eval(parse_only(code[i]), envir = envir))
res = if (v$visible) knit_print(v$value, inline = TRUE, options = opts_chunk$get())
res = hook_eval(code[i], envir)
if (inherits(res, 'knit_asis')) res = wrap(res, inline = TRUE)
d = nchar(input)
# replace with evaluated results
......
......@@ -141,7 +141,7 @@ cache_rx = '_[abcdef0123456789]{32}[.](rdb|rdx|RData)$'
#' object names in these files to automatically build cache dependencies, which
#' is similar to the effect of the \code{dependson} option. It is supposed to be
#' used in the first chunk of a document and this chunk must not be cached.
#' @param path the path to the dependency file
#' @param path Path to the dependency file.
#' @return \code{NULL}. The dependencies are built as a side effect.
#' @note Be cautious about \code{path}: because this function is used in a
#' chunk, the working directory when the chunk is evaluated is the directory
......@@ -196,15 +196,15 @@ parse_objects = function(path) {
#' chunk, which is normally not possible because \pkg{knitr} compiles the
#' document in a linear fashion, and objects created later cannot be used before
#' they are created.
#' @param label the chunk label of the code chunk that has a cache database
#' @param object the name of the object to be fetched from the database (if
#' missing, \code{NULL} is returned)
#' @param notfound a value to use when the \code{object} cannot be found
#' @param path the path of the cache database (normally set in the global chunk
#' option \code{cache.path})
#' @param lazy whether to \code{\link{lazyLoad}} the cache database (depending
#' @param label The chunk label of the code chunk that has a cache database.
#' @param object The name of the object to be fetched from the database. If it is
#' missing, \code{NULL} is returned).
#' @param notfound A value to use when the \code{object} cannot be found.
#' @param path Path of the cache database (normally set in the global chunk
#' option \code{cache.path}).
#' @param lazy Whether to \code{\link{lazyLoad}} the cache database (depending
#' on the chunk option \code{cache.lazy = TRUE} or \code{FALSE} of that code
#' chunk)
#' chunk).
#' @note Apparently this function loads the value of the object from the
#' \emph{previous} run of the document, which may be problematic when the
#' value of the object becomes different the next time the document is
......@@ -284,8 +284,8 @@ rand_seed = quote({
#' will not be automatically cleaned. You can use this function to identify
#' these possible files, and clean them if you are sure they are no longer
#' needed.
#' @param clean whether to remove the files
#' @param path the cache path
#' @param clean Boolean; whether to remove the files.
#' @param path Path to the cache.
#' @note The identification is not guaranteed to be correct, especially when
#' multiple documents share the same cache directory. You are recommended to
#' call \code{clean_cache(FALSE)} and carefully check the list of files (if
......
......@@ -17,18 +17,18 @@
#' often, so it is not a lot of work even if you just cut and paste such
#' bibliography entries from \code{toBibtex(citation())}.
#'
#' @param x package names (packages which are not installed are ignored)
#' @param file the (\file{.bib}) file to write (by default writes to the R
#' console; ignored if it is \code{NULL})
#' @param tweak whether to fix some known problems in the citations, especially
#' non-standard format of authors
#' @param width the width of lines in bibliographyb entries (if \code{NULL},
#' lines will not be wrapped)
#' @param prefix a prefix string for keys in BibTeX entries; by default, it is
#' @param x Package names. Packages which are not installed are ignored.
#' @param file The (\file{.bib}) file to write. By default, or if \code{NULL},
#' output is written to the R console.
#' @param tweak Whether to fix some known problems in the citations, especially
#' non-standard format of author names.
#' @param width Width of lines in bibliography entries. If \code{NULL},
#' lines will not be wrapped.
#' @param prefix Prefix string for keys in BibTeX entries; by default, it is
#' \samp{R-} unless \code{\link{option}('knitr.bib.prefix')} has been set to
#' another string
#' @return a list containing the citations (also written to the \code{file} as a
#' side effect)
#' another string.
#' @return A list containing the citations. Citations are also written to the \code{file} as a
#' side effect.
#' @note Some packages on CRAN do not have standard bib entries, which was once
#' reported by Michael Friendly at
#' \url{https://stat.ethz.ch/pipermail/r-devel/2010-November/058977.html}. I
......@@ -106,7 +106,7 @@ write_bib = function(
.tweak.bib = local({
x = read.csv(inst_dir('misc/tweak_bib.csv'), stringsAsFactors = FALSE)
x = x[order(xtfrm(x$package)), , drop = FALSE] # reorder entries by package names
write.csv(x, inst_dir('misc/tweak_bib.csv'), row.names = FALSE)
try_silent(write.csv(x, inst_dir('misc/tweak_bib.csv'), row.names = FALSE))
setNames(
lapply(x$author, function(a) c(author = sprintf(' author = {%s},', a))),
x$package
......
......@@ -11,18 +11,28 @@ new_defaults = function(value = list()) {
}
}
}
set = function(...) {
resolve = function(...) {
dots = list(...)
if (length(dots) == 0) return()
if (is.null(names(dots)) && length(dots) == 1 && is.list(dots[[1]]))
if (length(dots <- dots[[1]]) == 0) return()
defaults <<- merge(dots)
dots
}
set = function(...) {
dots = resolve(...)
if (length(dots)) defaults <<- merge(dots)
invisible(NULL)
}
merge = function(values) merge_list(defaults, values)
restore = function(target = value) defaults <<- target
append = function(...) {
dots = resolve(...)
for (i in names(dots)) dots[[i]] <- c(defaults[[i]], dots[[i]])
if (length(dots)) defaults <<- merge(dots)
invisible(NULL)
}
list(get = get, set = set, merge = merge, restore = restore)
list(get = get, set = set, append = append, merge = merge, restore = restore)
}
#' Default and current chunk options
......@@ -108,9 +118,9 @@ opts_chunk_attr = local({
#' We do not have to use the chunk option names given in \pkg{knitr}; we can set
#' aliases for them. The aliases are a named character vector; the names are
#' aliases and the elements in this vector are the real option names.
#' @param ... named arguments (argument names are aliases, and argument values
#' are real chunk options)
#' @return NULL (\code{opts_knit$get('aliases')} is modified as the side effect)
#' @param ... Named arguments. Argument names are aliases, and argument values
#' are real option names.
#' @return \code{NULL}. \code{opts_knit$get('aliases')} is modified as the side effect.
#' @export
#' @examples set_alias(w = 'fig.width', h = 'fig.height')
#' # then we can use options w and h in chunk headers instead of fig.width and fig.height
......
......@@ -35,18 +35,32 @@ knit_engines = new_defaults()
#'
#' If you have designed a language engine, you may call this function in the end
#' to format and return the text output from your engine.
#' @param options a list of chunk options (usually this is just the object
#'
#' For expert users, an advanced usage of this function is
#' \code{engine_output(options, out = LIST)} where \code{LIST} is a list that
#' has the same structure as the output of \code{evaluate::evaluate()}. In this
#' case, the arguments \code{code} and \code{extra} are ignored, and the list is
#' passed to an internal function \code{knitr:::wrap()} to return a character
#' vector of final output.
#' @param options A list of chunk options. Usually this is just the object
#' \code{options} passed to the engine function; see
#' \code{\link{knit_engines}})
#' @param code the source code of the chunk, to which the output hook
#' \code{source} is applied, unless the chunk option \code{echo == FALSE}
#' @param out the text output from the engine, to which the hook \code{output}
#' is applied, unless the chunk option \code{results == 'hide'}
#' @param extra any additional text output that you want to include
#' \code{\link{knit_engines}}.
#' @param code Source code of the chunk, to which the output hook
#' \code{source} is applied, unless the chunk option \code{echo} is \code{FALSE}.
#' @param out Text output from the engine, to which the hook \code{output}
#' is applied, unless the chunk option \code{results} is \code{'hide'}
#' @param extra Any additional text output that you want to include.
#' @return A character string generated from the source code and output using
#' the appropriate output hooks.
#' @export
#' @examples library(knitr)
#' engine_output(opts_chunk$merge(list(engine = 'Rscript')), code = '1 + 1', out = '[1] 2')
#' engine_output(opts_chunk$merge(list(echo = FALSE, engine = 'Rscript')), code = '1 + 1', out = '[1] 2')
#'
#' # expert use only
#' engine_output(opts_chunk$merge(list(engine = 'python')), out = list(structure(list(src = '1 + 1'), class = 'source'), '2'))
engine_output = function(options, code, out, extra = NULL) {
if (missing(code) && is.list(out)) return(unlist(wrap(out, options)))
if (!is.logical(options$echo)) code = code[options$echo]
if (length(code) != 1L) code = paste(code, collapse = '\n')
if (options$engine == 'sas' && length(out) > 1L && !grepl('[[:alnum:]]', out[2]))
......@@ -72,9 +86,7 @@ engine_output = function(options, code, out, extra = NULL) {
), collapse = '\n')
}
## TODO: how to emulate the console?? e.g. for Python
# see some experiments at https://github.com/yihui/runr
## command-line tools
eng_interpreted = function(options) {
engine = options$engine
code = if (engine %in% c('highlight', 'Rscript', 'sas', 'haskell', 'stata')) {
......@@ -106,7 +118,7 @@ eng_interpreted = function(options) {
f
)
} else paste(switch(
engine, bash = '-c', coffee = '-e', groovy = '-e', lein = 'exec -e',
engine, bash = '-c', coffee = '-e', groovy = '-e', lein = 'exec -ep',
mysql = '-e', node = '-e', octave = '--eval', perl = '-e', psql = '-c',
python = '-c', ruby = '-e', scala = '-e', sh = '-c', zsh = '-c', NULL
), shQuote(paste(options$code, collapse = '\n')))
......@@ -152,6 +164,20 @@ eng_shlib = function(options) {
engine_output(options, options$code, out)
}
## Python
eng_python = function(options) {
if (isFALSE(options$python.reticulate)) {
eng_interpreted(options)
} else {
if (!loadable('reticulate')) warning2(
"The 'python' engine in knitr requires the reticulate package. ",
"If you do not want to use the reticulate package, set the chunk option ",
"python.reticulate = FALSE."
)
reticulate::eng_python(options)
}
}
## Java
# e.g. see http://cran.rstudio.com/package=jvmr
......@@ -182,6 +208,11 @@ eng_Rcpp = function(options) {
engine_output(options, code, '')
}
## Julia
eng_julia = function(options) {
JuliaCall::eng_juliacall(options)
}
## Stan
## Compiles Stan model in the code chunk, creates a stanmodel object,
## and assigns it to a variable with the name given in engine.opts$x.
......@@ -348,7 +379,7 @@ eng_block = function(options) {
# convert the chunk content to HTML or LaTeX (ideally I only need to specify
# the markdown extension, but it is not implemented yet for LaTeX:
# https://github.com/jgm/pandoc/issues/2453)
if (is_pandoc) code = pandoc_fragment(code, to)
if (is_pandoc) code = pandoc_fragment(code, if (to == 'html') 'html4' else to)
l1 = options$latex.options
if (is.null(l1)) l1 = ''
h2 = options$html.tag %n% 'div'
......@@ -590,7 +621,7 @@ eng_go = function(options) {
local({
for (i in c(
'awk', 'bash', 'coffee', 'gawk', 'groovy', 'haskell', 'lein', 'mysql',
'node', 'octave', 'perl', 'psql', 'python', 'Rscript', 'ruby', 'sas',
'node', 'octave', 'perl', 'psql', 'Rscript', 'ruby', 'sas',
'scala', 'sed', 'sh', 'stata', 'zsh'
)) knit_engines$set(setNames(list(eng_interpreted), i))
})
......@@ -600,7 +631,8 @@ knit_engines$set(
highlight = eng_highlight, Rcpp = eng_Rcpp, tikz = eng_tikz, dot = eng_dot,
c = eng_shlib, fortran = eng_shlib, fortran95 = eng_shlib, asy = eng_dot,
cat = eng_cat, asis = eng_asis, stan = eng_stan, block = eng_block,
block2 = eng_block2, js = eng_js, css = eng_css, sql = eng_sql, go = eng_go
block2 = eng_block2, js = eng_js, css = eng_css, sql = eng_sql, go = eng_go,
python = eng_python, julia = eng_julia
)
get_engine = function(name) {
......
......@@ -94,11 +94,11 @@ insert_header_html = function(doc, b) {
#' type of output. For instance, we can change \code{highlight} to LaTeX
#' definitions of the \pkg{listings} package (and modify the output hooks
#' accordingly), so we can decorate R code using the \pkg{listings} package.
#' @param ... the header components; currently possible components are
#' @param ... Header components; currently possible components are
#' \code{highlight}, \code{tikz} and \code{framed}, which contain the
#' necessary commands to be used in the HTML header or LaTeX preamble; note
#' HTML output does not use the \code{tikz} and \code{framed} components (they
#' do not make sense to HTML)
#' necessary commands to be used in the HTML header or LaTeX preamble. Note that
#' HTML output does not use the \code{tikz} and \code{framed} components, since
#' they do not make sense in the context of HTML.
#' @return The header vector in \code{opts_knit} is set.
#' @export
#' @examples set_header(tikz = '\\usepackage{tikz}')
......
......@@ -46,7 +46,7 @@
#' \url{https://yihui.name/knitr/demo/cache/} for the meaning of \code{cache =
#' 2}).
#' @rdname chunk_hook
#' @param before,options,envir see references
#' @param before,options,envir See \emph{References} below.
#' @references \url{https://yihui.name/knitr/hooks/#chunk_hooks}
#' @seealso \code{\link[rgl]{rgl.snapshot}}, \code{\link[rgl]{rgl.postscript}},
#' \code{\link[rgl]{hook_rgl}}, \code{\link[rgl]{hook_webgl}}
......
......@@ -16,10 +16,10 @@
#' plots using \code{\link[grDevices]{recordPlot}}, and we can make use of these
#' hooks to insert graphics output in the output document; see
#' \code{\link{hook_plot_custom}} for details.
#' @param x the plot filename (a character string)
#' @param options a list of the current chunk options
#' @param x Filename for the plot (a character string).
#' @param options A list of the current chunk options.
#' @rdname hook_plot
#' @return A character string (code with plot filenames wrapped)
#' @return A character string of code, with plot filenames wrapped.
#' @references \url{https://yihui.name/knitr/hooks/}
#' @seealso \code{\link{hook_plot_custom}}
#' @export
......@@ -69,6 +69,12 @@ hook_plot_tex = function(x, options) {
fig.cur = options$fig.cur %n% 1L
fig.num = options$fig.num %n% 1L
animate = options$fig.show == 'animate'
fig.ncol = options$fig.ncol %n% fig.num
if (is.null(fig.sep <- options$fig.sep)) {
fig.sep = character(fig.num)
if (fig.ncol < fig.num) fig.sep[seq(fig.ncol, fig.num - 1L, fig.ncol)] = '\\newline'
}
sep.cur = NULL
# If this is a non-tikz animation, skip to the last fig.
if (!tikz && animate && fig.cur < fig.num) return('')
......@@ -110,6 +116,7 @@ hook_plot_tex = function(x, options) {
if (usesub) {
sub1 = sprintf('\\subfloat[%s%s]{', subcap, create_label(lab, fig.cur, latex = TRUE))
sub2 = '}'
sep.cur = fig.sep[fig.cur]; if (is.na(sep.cur)) sep.cur = NULL
}
# If pic is standalone/last in set:
......@@ -158,7 +165,7 @@ hook_plot_tex = function(x, options) {
if (is.null(lnk) || is.na(lnk)) res else sprintf('\\href{%s}{%s}', lnk, res)
},
resize2, sub2, align2, fig2
resize2, sub2, sep.cur, align2, fig2
)
}
......@@ -322,7 +329,7 @@ render_listings = function() {
#' behavior, use a comment \code{\% knitr_do_not_move} in the floating
#' environment.
#' @rdname hook_document
#' @param x a character string (the content of the whole document output)
#' @param x A character string (the whole output document).
#' @return The post-processed document as a character string.
#' @note These functions are hackish. Also note \code{hook_movecode()} assumes
#' you to use the default output hooks for LaTeX (not Sweave or listings), and
......
......@@ -5,7 +5,8 @@ hook_plot_md = function(x, options) {
if (is.null(to <- pandoc_to()) || is_html_output(to))
return(hook_plot_md_base(x, options))
if (!is.null(options$out.width) || !is.null(options$out.height) ||
!is.null(options$out.extra) || options$fig.align != 'default') {
!is.null(options$out.extra) || options$fig.align != 'default' ||
!is.null(options$fig.subcap)) {
if (to %in% c('beamer', 'latex')) {
# Pandoc < 1.13 does not support \caption[]{} so suppress short caption
if (is.null(options$fig.scap)) options$fig.scap = NA
......@@ -25,15 +26,6 @@ hook_plot_md = function(x, options) {
hook_plot_md_base(x, options)
}
# excludes can be a vector of 'markdown', 'epub', etc
is_html_output = function(fmt = pandoc_to(), excludes = NULL) {
if (length(fmt) == 0) return(FALSE)
if (grepl('^markdown', fmt)) fmt = 'markdown'
if (fmt == 'epub3') fmt = 'epub'
fmts = c('markdown', 'epub', 'html', 'html5', 'revealjs', 's5', 'slideous', 'slidy')
fmt %in% setdiff(fmts, excludes)
}
hook_plot_md_base = function(x, options) {
if (options$fig.show == 'animate') return(hook_plot_html(x, options))
......@@ -104,14 +96,14 @@ block_class = function(x){
#' @rdname output_hooks
#' @export
#' @param strict whether to use strict markdown or reST syntax; for markdown: if
#' @param strict Boolean; whether to use strict markdown or reST syntax. For markdown, if
#' \code{TRUE}, code blocks will be indented by 4 spaces, otherwise they are
#' put in fences made by three backticks; for reST, if \code{TRUE}, code is
#' put under two colons and indented by 4 spaces, otherwise is put under the
#' \samp{sourcecode} directive (e.g. it is useful for Sphinx)
#' @param fence_char a single character to be used in the code blocks fence
#' (e.g. it can be a backtick or a tilde, depending on your Markdown rendering
#' engine)
#' put in fences made by three backticks. For reST, if \code{TRUE}, code is
#' put under two colons and indented by 4 spaces, otherwise it is put under the
#' \samp{sourcecode} directive (this is useful for e.g. Sphinx).
#' @param fence_char A single character to be used in the code blocks fence.
#' This can be e.g. a backtick or a tilde, depending on your Markdown rendering
#' engine.
render_markdown = function(strict = FALSE, fence_char = '`') {
set_html_dev()
opts_knit$set(out.format = 'markdown')
......@@ -168,13 +160,13 @@ render_markdown = function(strict = FALSE, fence_char = '`') {
}
)
}
#' @param highlight which code highlighting engine to use: for \code{pygments},
#' the Liquid syntax is used (default approach Jekyll); for \code{prettify},
#' the output is prepared for the JavaScript library \file{prettify.js}; for
#' \code{none}, no highlighting engine will be used (code blocks are indented
#' by 4 spaces)
#' @param extra extra tags for the highlighting engine; for \code{pygments}, it
#' can be \code{'linenos'}; for \code{prettify}, it can be \code{'linenums'}
#' @param highlight Which code highlighting engine to use: if \code{pygments},
#' the Liquid syntax is used (default approach Jekyll); if \code{prettify},
#' the output is prepared for the JavaScript library \file{prettify.js}; if
#' \code{none}, no highlighting engine will be used, and code blocks are simply
#' indented by 4 spaces).
#' @param extra Extra tags for the highlighting engine. For \code{pygments}, this
#' can be \code{'linenos'}; for \code{prettify}, it can be \code{'linenums'}.
#' @rdname output_hooks
#' @export
render_jekyll = function(highlight = c('pygments', 'prettify', 'none'), extra = '') {
......
......@@ -10,7 +10,11 @@
source = .out.hook, output = .out.hook, warning = .out.hook,
message = .out.hook, error = .out.hook, plot = .plot.hook,
inline = .inline.hook, chunk = .out.hook, text = identity,
evaluate = evaluate::evaluate, document = identity
evaluate.inline = function(code, envir = knit_global()) {
v = withVisible(eval(parse_only(code), envir = envir))
if (v$visible) knit_print(v$value, inline = TRUE, options = opts_chunk$get())
},
evaluate = function(...) evaluate::evaluate(...), document = identity
)
#' Hooks for R code chunks, inline R code and output
......
......@@ -55,19 +55,19 @@
#' See the package website and manuals in the references to know more about
#' \pkg{knitr}, including the full documentation of chunk options and demos,
#' etc.
#' @param input path of the input file
#' @param output path of the output file for \code{knit()}; if \code{NULL}, this
#' function will try to guess and it will be under the current working
#' directory
#' @param tangle whether to tangle the R code from the input file (like
#' \code{\link[utils]{Stangle}})
#' @param text a character vector as an alternative way to provide the input
#' file
#' @param quiet whether to suppress the progress bar and messages
#' @param envir the environment in which the code chunks are to be evaluated
#' (for example, \code{\link{parent.frame}()}, \code{\link{new.env}()}, or
#' \code{\link{globalenv}()})
#' @param encoding the encoding of the input file; see \code{\link{file}}
#' @param input Path to the input file.
#' @param output Path to the output file for \code{knit()}. If \code{NULL}, this
#' function will try to guess a default, which will be under the current working
#' directory.
#' @param tangle Boolean; whether to tangle the R code from the input file (like
#' \code{\link[utils]{Stangle}}).
#' @param text A character vector. This is an alternative way to provide the input
#' file.
#' @param quiet Boolean; suppress the progress bar and messages?
#' @param envir Environment in which code chunks are to be evaluated,
#' for example, \code{\link{parent.frame}()}, \code{\link{new.env}()}, or
#' \code{\link{globalenv}()}).
#' @param encoding Encoding of the input file; see \code{\link{file}}.
#' @return The compiled document is written into the output file, and the path
#' of the output file is returned. If the \code{text} argument is not
#' \code{NULL}, the compiled output is returned as a character vector. In
......@@ -274,10 +274,10 @@ knit = function(input, output = NULL, tangle = FALSE, text = NULL, quiet = FALSE
output %n% res
}
#' @rdname knit
#' @param documentation an integer specifying the level of documentation to go
#' the tangled script: \code{0} means pure code (discard all text chunks);
#' \code{1} (default) means add the chunk headers to code; \code{2} means add
#' all text chunks to code as roxygen comments
#' @param documentation An integer specifying the level of documentation to add to
#' the tangled script. \code{0} means to output pure code, discarding all text chunks);
#' \code{1} (the default) means to add the chunk headers to the code; \code{2} means to
#' add all text chunks to code as roxygen comments.
#' @param ... arguments passed to \code{\link{knit}()} from \code{purl()}
#' @export
purl = function(..., documentation = 1L) {
......@@ -368,11 +368,11 @@ auto_format = function(ext) {
#' the result into the main document. It is designed to be used in the chunk
#' option \code{child} and serves as the alternative to the
#' \command{SweaveInput} command in Sweave.
#' @param ... arguments passed to \code{\link{knit}}
#' @param options a list of chunk options to be used as global options inside
#' the child document (ignored if not a list); when one uses the \code{child}
#' @param ... Arguments passed to \code{\link{knit}}.
#' @param options A list of chunk options to be used as global options inside
#' the child document. When one uses the \code{child}
#' option in a parent chunk, the chunk options of the parent chunk will be
#' passed to the \code{options} argument here
#' passed to the \code{options} argument here. Ignored if not a list.
#' @inheritParams knit
#' @return A character string of the content of the compiled child document is
#' returned as a character string so it can be written back to the parent
......@@ -413,10 +413,10 @@ knit_child = function(..., options = NULL, envir = knit_global()) {
#' Sometimes we may want to exit the knitting process early, and completely
#' ignore the rest of the document. This function provides a mechanism to
#' terminate \code{\link{knit}()}.
#' @param append a character vector to be appended to the results from
#' \code{knit()} so far; by default, it is \samp{\end{document}} for LaTeX
#' output, and \samp{</body></html>} for HTML output to make the output
#' document complete; for other types of output, it is an empty string
#' @param append A character vector to be appended to the results from
#' \code{knit()} so far. By default, this is \samp{\end{document}} for LaTeX
#' output, and \samp{</body></html>} for HTML output, to make the output
#' document complete. For other types of output, it is an empty string.
#' @return Invisible \code{NULL}. An internal signal is set up (as a side
#' effect) to notify \code{knit()} to quit as if it had reached the end of the
#' document.
......@@ -434,7 +434,7 @@ knit_log = new_defaults() # knitr log for errors, warnings and messages
#' Wrap evaluated results for output
#'
#' @param x output from \code{\link[evaluate]{evaluate}}
#' @param options list of options used to control output
#' @param options List of options used to control output
#' @noRd
wrap = function(x, options = list(), ...) {
UseMethod('wrap', x)
......@@ -572,7 +572,7 @@ wrap.knit_image_paths = function(x, options = opts_chunk$get(), inline = FALSE)
}
dpi = attr(x, 'dpi') %n% options$dpi
paste(unlist(lapply(seq_along(x), function(i) {
options$fig.cur = i
options$fig.cur = plot_counter()
if (is.null(options[['out.width']]))
options['out.width'] = list(raster_dpi_width(x[i], dpi))
hook_plot(x[i], reduce_plot_opts(options))
......@@ -631,10 +631,10 @@ add_html_caption = function(options, code) {
#' method \code{knit_print.data.frame} that turns a data.frame into a table (the
#' implementation may use other R packages or functions, e.g. \pkg{xtable} or
#' \code{\link{kable}()}).
#' @param x an R object to be printed
#' @param ... additional arguments passed to the S3 method (currently ignored,
#' @param x An R object to be printed