From 223903f770990edbd7a55824b32a4c2cd357e38a Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Tue, 8 Dec 2020 22:00:44 -0600 Subject: [PATCH 01/15] export block_exec funs --- R/block.R | 6 ++++++ man/Sweave2knitr.Rd | 18 ++++++++--------- man/all_labels.Rd | 6 +++--- man/all_patterns.Rd | 3 +-- man/asis_output.Rd | 2 +- man/chunk_hook.Rd | 2 +- man/combine_words.Rd | 11 +++++------ man/engine_output.Rd | 10 +++------- man/fig_chunk.Rd | 8 ++++---- man/fig_path.Rd | 4 ++-- man/hook_document.Rd | 4 +--- man/hook_plot.Rd | 7 +++---- man/image_uri.Rd | 7 +++---- man/imgur_upload.Rd | 13 +++++------- man/inline_expr.Rd | 4 +--- man/kable.Rd | 44 ++++++++++++++++++++--------------------- man/knit.Rd | 4 ++-- man/knit2html.Rd | 9 ++++----- man/knit_child.Rd | 4 ++-- man/knit_engines.Rd | 3 +-- man/knit_expand.Rd | 2 +- man/knit_filter.Rd | 17 ++++++++-------- man/knit_hooks.Rd | 3 +-- man/knit_patterns.Rd | 8 ++++---- man/knit_print.Rd | 8 ++++---- man/knit_rd.Rd | 8 ++++---- man/knit_theme.Rd | 7 +++---- man/opts_chunk.Rd | 3 +-- man/opts_hooks.Rd | 8 ++++---- man/opts_knit.Rd | 9 ++++----- man/output_type.Rd | 2 +- man/pandoc.Rd | 2 +- man/pat_fun.Rd | 4 +--- man/rand_seed.Rd | 2 +- man/raw_block.Rd | 2 +- man/raw_output.Rd | 9 +++------ man/read_chunk.Rd | 23 +++++++++++---------- man/read_rforge.Rd | 8 +++----- man/rocco.Rd | 18 +++++++---------- man/set_alias.Rd | 5 ++--- man/set_header.Rd | 4 ++-- man/stitch.Rd | 8 ++++---- man/vignette_engines.Rd | 8 ++++---- man/wrap_rmd.Rd | 4 ++-- man/write_bib.Rd | 14 ++++++------- 45 files changed, 162 insertions(+), 193 deletions(-) diff --git a/R/block.R b/R/block.R index d57d4b3792..f86fc69f07 100644 --- a/R/block.R +++ b/R/block.R @@ -100,6 +100,7 @@ cache2.opts = c('fig.keep', 'fig.path', 'fig.ext', 'dev', 'dpi', 'dev.args', 'fi # options that should not affect cache cache0.opts = c('include', 'out.width.px', 'out.height.px', 'cache.rebuild') +#' @export block_exec = function(options) { # when code is not R language if (options$engine != 'R') { @@ -118,8 +119,13 @@ block_exec = function(options) { )) } return(if (options$include) output else '') + } else if (options$engine == "R") { + block_exec_R(options) } +} +#' @export +block_exec_R = function(options) { # eval chunks (in an empty envir if cache) env = knit_global() obj.before = ls(globalenv(), all.names = TRUE) # global objects before chunk diff --git a/man/Sweave2knitr.Rd b/man/Sweave2knitr.Rd index 657ed1c40e..2becef3825 100644 --- a/man/Sweave2knitr.Rd +++ b/man/Sweave2knitr.Rd @@ -68,17 +68,17 @@ If \samp{\\SweaveOpts{}} spans across multiple lines, it will not be is supported. } \examples{ -Sweave2knitr(text = "<>=") # this is valid -Sweave2knitr(text = "<>=") # dev='png' -Sweave2knitr(text = "<>=") -Sweave2knitr(text = "<<,png=false,fig=TRUE>>=") -Sweave2knitr(text = "\\\\SweaveOpts{echo=false}") -Sweave2knitr(text = "\\\\SweaveInput{hello.Rnw}") +Sweave2knitr(text='<>=') # this is valid +Sweave2knitr(text="<>=") # dev='png' +Sweave2knitr(text="<>=") +Sweave2knitr(text="<<,png=false,fig=TRUE>>=") +Sweave2knitr(text="\\\\SweaveOpts{echo=false}") +Sweave2knitr(text="\\\\SweaveInput{hello.Rnw}") # Sweave example in utils testfile = system.file("Sweave", "Sweave-test-1.Rnw", package = "utils") -Sweave2knitr(testfile, output = "Sweave-test-knitr.Rnw") -if (interactive()) knit("Sweave-test-knitr.Rnw") # or knit2pdf() directly -unlink("Sweave-test-knitr.Rnw") +Sweave2knitr(testfile, output = 'Sweave-test-knitr.Rnw') +if (interactive()) knit('Sweave-test-knitr.Rnw') # or knit2pdf() directly +unlink('Sweave-test-knitr.Rnw') } \references{ The motivation of the changes in the syntax: diff --git a/man/all_labels.Rd b/man/all_labels.Rd index aca44d1c38..914b3ec19b 100644 --- a/man/all_labels.Rd +++ b/man/all_labels.Rd @@ -42,8 +42,8 @@ Empty code chunks are always ignored, including those chunks that are \examples{ # the examples below are meaningless unless you put them in a knitr document all_labels() -all_labels(engine == "Rcpp") -all_labels(echo == FALSE && results != "hide") +all_labels(engine == 'Rcpp') +all_labels(echo == FALSE && results != 'hide') # or separate the two conditions -all_labels(echo == FALSE, results != "hide") +all_labels(echo == FALSE, results != 'hide') } diff --git a/man/all_patterns.Rd b/man/all_patterns.Rd index 4bd133e680..811139e87a 100644 --- a/man/all_patterns.Rd +++ b/man/all_patterns.Rd @@ -14,8 +14,7 @@ all_patterns This object is a named list of all built-in patterns. } \examples{ -all_patterns$rnw -all_patterns$html +all_patterns$rnw; all_patterns$html str(all_patterns) } diff --git a/man/asis_output.Rd b/man/asis_output.Rd index a96db47c49..9e6dffb240 100644 --- a/man/asis_output.Rd +++ b/man/asis_output.Rd @@ -48,5 +48,5 @@ This function only works in top-level R expressions, and it will not \url{https://github.com/yihui/knitr/issues/1137} for a discussion. } \examples{ -# see ?knit_print + # see ?knit_print } diff --git a/man/chunk_hook.Rd b/man/chunk_hook.Rd index 8938b7f685..8d01f7702a 100644 --- a/man/chunk_hook.Rd +++ b/man/chunk_hook.Rd @@ -75,7 +75,7 @@ The two hook functions \code{hook_rgl()} and \code{hook_webgl()} were \pkg{knitr} v1.10.5, and you can \code{library(rgl)} to get them. } \examples{ -if (require("rgl") && exists("hook_rgl")) knit_hooks$set(rgl = hook_rgl) +if (require('rgl') && exists('hook_rgl')) knit_hooks$set(rgl = hook_rgl) # then in code chunks, use the option rgl=TRUE } \references{ diff --git a/man/combine_words.Rd b/man/combine_words.Rd index f02a8df3a8..e4faca80bd 100644 --- a/man/combine_words.Rd +++ b/man/combine_words.Rd @@ -31,10 +31,9 @@ greater than 2, \code{sep} is used to separate all words, and the \code{and} string is prepended to the last word. } \examples{ -combine_words("a") -combine_words(c("a", "b")) -combine_words(c("a", "b", "c")) -combine_words(c("a", "b", "c"), sep = " / ", and = "") -combine_words(c("a", "b", "c"), and = "") -combine_words(c("a", "b", "c"), before = "\"", after = "\"") +combine_words('a'); combine_words(c('a', 'b')) +combine_words(c('a', 'b', 'c')) +combine_words(c('a', 'b', 'c'), sep = ' / ', and = '') +combine_words(c('a', 'b', 'c'), and = '') +combine_words(c('a', 'b', 'c'), before = '"', after = '"') } diff --git a/man/engine_output.Rd b/man/engine_output.Rd index aaaa02acdf..2d8a957609 100644 --- a/man/engine_output.Rd +++ b/man/engine_output.Rd @@ -37,13 +37,9 @@ vector of final output. } \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") +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(opts_chunk$merge(list(engine = 'python')), out = list(structure(list(src = '1 + 1'), class = 'source'), '2')) } diff --git a/man/fig_chunk.Rd b/man/fig_chunk.Rd index 97e088f751..ca2d6b89c7 100644 --- a/man/fig_chunk.Rd +++ b/man/fig_chunk.Rd @@ -39,8 +39,8 @@ this function if you want to show them elsewhere. } \examples{ library(knitr) -fig_chunk("foo", "png") -fig_chunk("foo", "pdf") -fig_chunk("foo", "svg", 2) # the second plot of the chunk foo -fig_chunk("foo", "png", 1:5) # if the chunk foo produced 5 plots +fig_chunk('foo', 'png') +fig_chunk('foo', 'pdf') +fig_chunk('foo', 'svg', 2) # the second plot of the chunk foo +fig_chunk('foo', 'png', 1:5) # if the chunk foo produced 5 plots } diff --git a/man/fig_path.Rd b/man/fig_path.Rd index ebb4623637..0bb84749f3 100644 --- a/man/fig_path.Rd +++ b/man/fig_path.Rd @@ -31,6 +31,6 @@ When there are special characters (not alphanumeric or \samp{-} or makes the filenames safe to LaTeX. } \examples{ -fig_path(".pdf", options = list(fig.path = "figure/abc-", label = "first-plot")) -fig_path(".png", list(fig.path = "foo-", label = "bar"), 1:10) +fig_path('.pdf', options = list(fig.path='figure/abc-', label='first-plot')) +fig_path('.png', list(fig.path='foo-', label='bar'), 1:10) } diff --git a/man/hook_document.Rd b/man/hook_document.Rd index 60cc6dcb00..f164c2603d 100644 --- a/man/hook_document.Rd +++ b/man/hook_document.Rd @@ -32,9 +32,7 @@ These functions are hackish. Also note \code{hook_movecode()} assumes every figure/table environment must have a label. } \examples{ -\dontrun{ -knit_hooks$set(document = hook_movecode) -} +\dontrun{knit_hooks$set(document = hook_movecode)} # see example 103 at https://github.com/yihui/knitr-examples } \references{ diff --git a/man/hook_plot.Rd b/man/hook_plot.Rd index ed48320c42..19dc7c49c6 100644 --- a/man/hook_plot.Rd +++ b/man/hook_plot.Rd @@ -53,16 +53,15 @@ these hooks to insert graphics output in the output document; see # this is what happens for a chunk like this # <>= -hook_plot_tex("foo-bar-plot.pdf", opts_chunk$merge(list(fig.align = "right"))) +hook_plot_tex('foo-bar-plot.pdf', opts_chunk$merge(list(fig.align='right'))) # <>= -hook_plot_tex("bar.tikz", opts_chunk$merge(list(dev = "tikz"))) +hook_plot_tex('bar.tikz', opts_chunk$merge(list(dev='tikz'))) # <>= # 5 plots are generated in this chunk -hook_plot_tex("foo5.pdf", opts_chunk$merge(list(fig.show = "animate", interval = 0.1, - fig.cur = 5, fig.num = 5))) +hook_plot_tex('foo5.pdf', opts_chunk$merge(list(fig.show='animate',interval=.1,fig.cur=5, fig.num=5))) } \references{ \url{https://yihui.org/knitr/hooks/} diff --git a/man/image_uri.Rd b/man/image_uri.Rd index 25ec53d4ed..b8d6a0e0f5 100644 --- a/man/image_uri.Rd +++ b/man/image_uri.Rd @@ -18,10 +18,9 @@ different function name). It can encode an image file as a base64 string, which can be used in the \code{img} tag in HTML. } \examples{ -uri = image_uri(file.path(R.home("doc"), "html", "logo.jpg")) -if (interactive()) { - cat(sprintf("", uri), file = "logo.html") - browseURL("logo.html") # you can check its HTML source +uri = image_uri(file.path(R.home('doc'), 'html', 'logo.jpg')) +if (interactive()) {cat(sprintf('', uri), file = 'logo.html') +browseURL('logo.html') # you can check its HTML source } } \references{ diff --git a/man/imgur_upload.Rd b/man/imgur_upload.Rd index b7477d5f90..f6b9496df3 100644 --- a/man/imgur_upload.Rd +++ b/man/imgur_upload.Rd @@ -36,19 +36,16 @@ Please register your own Imgur application to get your client ID; you } \examples{ \dontrun{ -f = tempfile(fileext = ".png") -png(f) -plot(rnorm(100), main = R.version.string) -dev.off() +f = tempfile(fileext = '.png') +png(f); plot(rnorm(100), main = R.version.string); dev.off() res = imgur_upload(f) res # link to original URL of the image -attr(res, "XML") # all information -if (interactive()) - browseURL(res) +attr(res, 'XML') # all information +if (interactive()) browseURL(res) # to use your own key -opts_knit$set(upload.fun = function(file) imgur_upload(file, key = "your imgur key")) +opts_knit$set(upload.fun = function(file) imgur_upload(file, key = 'your imgur key')) } } \references{ diff --git a/man/inline_expr.Rd b/man/inline_expr.Rd index dedce8cfc7..f6c194034f 100644 --- a/man/inline_expr.Rd +++ b/man/inline_expr.Rd @@ -25,7 +25,5 @@ R Markdown document, you may write \samp{`` `r knitr::inline_expr('1+1')` } \examples{ library(knitr) -inline_expr("1+1", "rnw") -inline_expr("1+1", "html") -inline_expr("1+1", "md") +inline_expr('1+1', 'rnw'); inline_expr('1+1', 'html'); inline_expr('1+1', 'md') } diff --git a/man/kable.Rd b/man/kable.Rd index ee2099d4bb..ed9367c139 100644 --- a/man/kable.Rd +++ b/man/kable.Rd @@ -90,45 +90,43 @@ When using \code{kable()} as a \emph{top-level} expression, you do not \code{\link{for}} loop), you must explicitly \code{print(kable(...))}. } \examples{ -d1 = head(iris) -d2 = head(mtcars) +d1 = head(iris); d2 = head(mtcars) # pipe tables by default kable(d1) kable(d2[, 1:5]) # no inner padding -kable(d2, format = "pipe", padding = 0) +kable(d2, format = 'pipe', padding = 0) # more padding -kable(d2, format = "pipe", padding = 2) -kable(d1, format = "latex") -kable(d1, format = "html") -kable(d1, format = "latex", caption = "Title of the table") -kable(d1, format = "html", caption = "Title of the table") +kable(d2, format = 'pipe', padding = 2) +kable(d1, format = 'latex') +kable(d1, format = 'html') +kable(d1, format = 'latex', caption = 'Title of the table') +kable(d1, format = 'html', caption = 'Title of the table') # use the booktabs package -kable(mtcars, format = "latex", booktabs = TRUE) +kable(mtcars, format = 'latex', booktabs = TRUE) # use the longtable package -kable(matrix(1000, ncol = 5), format = "latex", digits = 2, longtable = TRUE) +kable(matrix(1000, ncol=5), format = 'latex', digits = 2, longtable = TRUE) # change LaTeX default table environment -kable(d1, format = "latex", caption = "My table", table.envir = "table*") +kable(d1, format = "latex", caption = "My table", table.envir='table*') # add some table attributes -kable(d1, format = "html", table.attr = "id=\"mytable\"") +kable(d1, format = 'html', table.attr = 'id="mytable"') # reST output -kable(d2, format = "rst") +kable(d2, format = 'rst') # no row names -kable(d2, format = "rst", row.names = FALSE) +kable(d2, format = 'rst', row.names = FALSE) # Pandoc simple tables -kable(d2, format = "simple", caption = "Title of the table") +kable(d2, format = 'simple', caption = 'Title of the table') # format numbers using , as decimal point, and ' as thousands separator -x = as.data.frame(matrix(rnorm(60, 1e+06, 10000), 10)) -kable(x, format.args = list(decimal.mark = ",", big.mark = "'")) +x = as.data.frame(matrix(rnorm(60, 1e6, 1e4), 10)) +kable(x, format.args = list(decimal.mark = ',', big.mark = "'")) # save the value -x = kable(d2, format = "html") -cat(x, sep = "\n") +x = kable(d2, format = 'html') +cat(x, sep = '\n') # can also set options(knitr.table.format = 'html') so that the output is HTML -# multiple tables via either kable(list(x1, x2)) or kables(list(kable(x1), -# kable(x2))) -kable(list(d1, d2), caption = "A tale of two tables") -kables(list(kable(d1, align = "l"), kable(d2)), caption = "A tale of two tables") +# multiple tables via either kable(list(x1, x2)) or kables(list(kable(x1), kable(x2))) +kable(list(d1, d2), caption = 'A tale of two tables') +kables(list(kable(d1, align = 'l'), kable(d2)), caption = 'A tale of two tables') } \references{ See diff --git a/man/knit.Rd b/man/knit.Rd index 9ddfc7ef76..b2cc5506e9 100644 --- a/man/knit.Rd +++ b/man/knit.Rd @@ -149,14 +149,14 @@ The working directory when evaluating R code chunks is the directory of } \examples{ library(knitr) -(f = system.file("examples", "knitr-minimal.Rnw", package = "knitr")) +(f = system.file('examples', 'knitr-minimal.Rnw', package = 'knitr')) knit(f) # compile to tex purl(f) # tangle R code purl(f, documentation = 0) # extract R code only purl(f, documentation = 2) # also include documentation -unlink(c("knitr-minimal.tex", "knitr-minimal.R", "figure"), recursive = TRUE) +unlink(c('knitr-minimal.tex', 'knitr-minimal.R', 'figure'), recursive = TRUE) } \references{ Package homepage: \url{https://yihui.org/knitr/}. The \pkg{knitr} diff --git a/man/knit2html.Rd b/man/knit2html.Rd index dca88c3435..5ff0c63d52 100644 --- a/man/knit2html.Rd +++ b/man/knit2html.Rd @@ -57,12 +57,11 @@ The \pkg{markdown} package is for R Markdown v1, which is much less } \examples{ # a minimal example -writeLines(c("# hello markdown", "```{r hello-random, echo=TRUE}", "rnorm(5)", "```"), - "test.Rmd") -knit2html("test.Rmd") -if (interactive()) browseURL("test.html") +writeLines(c("# hello markdown", '```{r hello-random, echo=TRUE}', 'rnorm(5)', '```'), 'test.Rmd') +knit2html('test.Rmd') +if (interactive()) browseURL('test.html') -unlink(c("test.Rmd", "test.html", "test.md")) +unlink(c('test.Rmd', 'test.html', 'test.md')) } \seealso{ \code{\link{knit}}, \code{markdown::\link{markdownToHTML}} diff --git a/man/knit_child.Rd b/man/knit_child.Rd index bf3ecc8f23..5d2526f239 100644 --- a/man/knit_child.Rd +++ b/man/knit_child.Rd @@ -37,8 +37,8 @@ This function is not supposed be called directly like The path of the child document is determined relative to the parent document. } \examples{ -# you can write \Sexpr{knit_child('child-doc.Rnw')} in an Rnw file 'main.Rnw' to -# input results from child-doc.Rnw in main.tex +# you can write \Sexpr{knit_child('child-doc.Rnw')} in an Rnw file 'main.Rnw' +# to input results from child-doc.Rnw in main.tex # comment out the child doc by \Sexpr{knit_child('child-doc.Rnw', eval = FALSE)} } diff --git a/man/knit_engines.Rd b/man/knit_engines.Rd index dae268b480..1c58edc3d5 100644 --- a/man/knit_engines.Rd +++ b/man/knit_engines.Rd @@ -40,8 +40,7 @@ The Leiningen engine \code{lein} requires lein-exec plugin; see \url{https://github.com/yihui/knitr/issues/1176} for details. } \examples{ -knit_engines$get("python") -knit_engines$get("awk") +knit_engines$get('python'); knit_engines$get('awk') names(knit_engines$get()) } \references{ diff --git a/man/knit_expand.Rd b/man/knit_expand.Rd index 501bd900a1..7cf69fe0f5 100644 --- a/man/knit_expand.Rd +++ b/man/knit_expand.Rd @@ -29,7 +29,7 @@ template. } \examples{ # see the knit_expand vignette -if (interactive()) browseVignettes(package = "knitr") +if (interactive()) browseVignettes(package='knitr') } \references{ This function was inspired by the pyexpander and m4 diff --git a/man/knit_filter.Rd b/man/knit_filter.Rd index 9beec4409d..cc5b0fcadd 100644 --- a/man/knit_filter.Rd +++ b/man/knit_filter.Rd @@ -24,14 +24,13 @@ and inline expressions. } \examples{ library(knitr) -knitr_example = function(...) system.file("examples", ..., package = "knitr") +knitr_example = function(...) system.file('examples', ..., package = 'knitr') \donttest{ -if (Sys.which("aspell") != "") { - # -t means the TeX mode - utils::aspell(knitr_example("knitr-minimal.Rnw"), knit_filter, control = "-t") - - # -H is the HTML mode - utils::aspell(knitr_example("knitr-minimal.Rmd"), knit_filter, control = "-H -t") -} -} +if (Sys.which('aspell') != '') { +# -t means the TeX mode +utils::aspell(knitr_example('knitr-minimal.Rnw'), knit_filter, control = '-t') + +# -H is the HTML mode +utils::aspell(knitr_example('knitr-minimal.Rmd'), knit_filter, control = '-H -t') +}} } diff --git a/man/knit_hooks.Rd b/man/knit_hooks.Rd index fdebf7775d..7f3ff1621d 100644 --- a/man/knit_hooks.Rd +++ b/man/knit_hooks.Rd @@ -16,8 +16,7 @@ arguments and returns desired output. The object \code{knit_hooks} is used to access or set hooks in this package. } \examples{ -knit_hooks$get("source") -knit_hooks$get("inline") +knit_hooks$get('source'); knit_hooks$get('inline') } \references{ Usage: \url{https://yihui.org/knitr/objects/} diff --git a/man/knit_patterns.Rd b/man/knit_patterns.Rd index 3e207f5489..a5d6a2b290 100644 --- a/man/knit_patterns.Rd +++ b/man/knit_patterns.Rd @@ -19,18 +19,18 @@ and examples for usage. All built-in patterns are available in the list } \examples{ library(knitr) -opat = knit_patterns$get() # old pattern list (to restore later) +opat = knit_patterns$get() # old pattern list (to restore later) apats = all_patterns # a list of all built-in patterns str(apats) -knit_patterns$set(apats[["rnw"]]) # set pattern list from apats +knit_patterns$set(apats[['rnw']]) # set pattern list from apats -knit_patterns$get(c("chunk.begin", "chunk.end", "inline.code")) +knit_patterns$get(c('chunk.begin', 'chunk.end', 'inline.code')) # a customized pattern list; has to empty the original patterns first! knit_patterns$restore() # we may want to use this in an HTML document -knit_patterns$set(list(chunk.begin = "")) +knit_patterns$set(list(chunk.begin = '')) str(knit_patterns$get()) knit_patterns$set(opat) # put the old patterns back diff --git a/man/knit_print.Rd b/man/knit_print.Rd index e93d8571a7..d13bca3a8d 100644 --- a/man/knit_print.Rd +++ b/man/knit_print.Rd @@ -45,13 +45,13 @@ It is recommended to leave a \code{...} argument in your method, to library(knitr) # write tables for data frames knit_print.data.frame = function(x, ...) { - res = paste(c("", "", kable(x, output = FALSE)), collapse = "\n") - asis_output(res) + res = paste(c('', '', kable(x, output = FALSE)), collapse = '\n') + asis_output(res) } # register the method registerS3method("knit_print", "data.frame", knit_print.data.frame) -# after you define and register the above method, data frames will be printed as -# tables in knitr, which is different with the default print() behavior +# after you define and register the above method, data frames will be printed +# as tables in knitr, which is different with the default print() behavior } \references{ See \code{vignette('knit_print', package = 'knitr')}. diff --git a/man/knit_rd.Rd b/man/knit_rd.Rd index 062266210d..097aebcc5e 100644 --- a/man/knit_rd.Rd +++ b/man/knit_rd.Rd @@ -38,10 +38,10 @@ Ideally the html pages should be put under the \file{html} directory of library(knitr) \dontrun{ -knit_rd("maps") -knit_rd("rpart") -setwd(system.file("html", package = "ggplot2")) -knit_rd("ggplot2") # time-consuming! +knit_rd('maps') +knit_rd('rpart') +setwd(system.file('html', package = 'ggplot2')) +knit_rd('ggplot2') # time-consuming! knit_rd_all() # this may take really long time if you have many packages installed } diff --git a/man/knit_theme.Rd b/man/knit_theme.Rd index b58b8f76dc..2c5e5916b2 100644 --- a/man/knit_theme.Rd +++ b/man/knit_theme.Rd @@ -28,15 +28,14 @@ The syntax highlighting here only applies to \file{.Rnw} (LaTeX) and highlighting themes; see \url{https://rmarkdown.rstudio.com}). } \examples{ -opts_knit$set(out.format = "latex") -knit_theme$set("edit-vim") +opts_knit$set(out.format='latex'); knit_theme$set('edit-vim') knit_theme$get() # names of all available themes -thm = knit_theme$get("acid") # parse the theme to a list +thm = knit_theme$get('acid') # parse the theme to a list knit_theme$set(thm) -opts_knit$set(out.format = NULL) # restore option +opts_knit$set(out.format=NULL) # restore option } \references{ For a preview of all themes, see diff --git a/man/opts_chunk.Rd b/man/opts_chunk.Rd index 933d069d6c..29b16f5f25 100644 --- a/man/opts_chunk.Rd +++ b/man/opts_chunk.Rd @@ -38,8 +38,7 @@ See \code{str(knitr::opts_chunk$get())} for a list of default chunk options. not recommended to do so unless you understand the consequences. } \examples{ -opts_chunk$get("prompt") -opts_chunk$get("fig.keep") +opts_chunk$get('prompt'); opts_chunk$get('fig.keep') } \references{ Usage: \url{https://yihui.org/knitr/objects/} diff --git a/man/opts_hooks.Rd b/man/opts_hooks.Rd index 6673d7eabe..d2e0b59689 100644 --- a/man/opts_hooks.Rd +++ b/man/opts_hooks.Rd @@ -24,10 +24,10 @@ will be called to update the chunk options. \examples{ # make sure the figure width is no smaller than fig.height opts_hooks$set(fig.width = function(options) { - if (options$fig.width < options$fig.height) { - options$fig.width = options$fig.height - } - options + if (options$fig.width < options$fig.height) { + options$fig.width = options$fig.height + } + options }) # remove all hooks opts_hooks$restore() diff --git a/man/opts_knit.Rd b/man/opts_knit.Rd index 9d7e4415be..4c5ca19140 100644 --- a/man/opts_knit.Rd +++ b/man/opts_knit.Rd @@ -26,12 +26,11 @@ options in \file{~/.Rprofile} without loading \pkg{knitr}. See \code{str(knitr::opts_knit$get())} for a list of default package options. } \examples{ -opts_knit$get("verbose") -opts_knit$set(verbose = TRUE) # change it +opts_knit$get('verbose'); opts_knit$set(verbose = TRUE) # change it if (interactive()) { - # for unnamed chunks, use 'fig' as the figure prefix - opts_knit$set(unnamed.chunk.label = "fig") - knit("001-minimal.Rmd") # from https://github.com/yihui/knitr-examples +# for unnamed chunks, use 'fig' as the figure prefix +opts_knit$set(unnamed.chunk.label='fig') +knit('001-minimal.Rmd') # from https://github.com/yihui/knitr-examples } } \references{ diff --git a/man/output_type.Rd b/man/output_type.Rd index 62270b4333..6aeedc4f41 100644 --- a/man/output_type.Rd +++ b/man/output_type.Rd @@ -37,5 +37,5 @@ default, these formats are considered as HTML formats: \code{c('markdown', \examples{ knitr::is_latex_output() knitr::is_html_output() -knitr::is_html_output(excludes = c("markdown", "epub")) +knitr::is_html_output(excludes = c('markdown', 'epub')) } diff --git a/man/pandoc.Rd b/man/pandoc.Rd index 79d7f32fee..75f6d0eb75 100644 --- a/man/pandoc.Rd +++ b/man/pandoc.Rd @@ -51,7 +51,7 @@ input markdown file will be converted to all these formats by default, unless the \code{format} argument is specified as one single format. } \examples{ -system("pandoc -h") # see possible output formats +system('pandoc -h') # see possible output formats } \references{ Pandoc: \url{https://pandoc.org}; Examples and rules of the diff --git a/man/pat_fun.Rd b/man/pat_fun.Rd index e6ccfb5ec2..839b17fe4c 100644 --- a/man/pat_fun.Rd +++ b/man/pat_fun.Rd @@ -39,9 +39,7 @@ documents. } \examples{ # see how knit_patterns is modified -knit_patterns$get() -pat_rnw() -knit_patterns$get() +knit_patterns$get(); pat_rnw(); knit_patterns$get() knit_patterns$restore() # empty the list } diff --git a/man/rand_seed.Rd b/man/rand_seed.Rd index 4c540a4416..cf39cf0205 100644 --- a/man/rand_seed.Rd +++ b/man/rand_seed.Rd @@ -18,7 +18,7 @@ references. } \examples{ eval(rand_seed) -rnorm(1) # .Random.seed is created (or modified) +rnorm(1) # .Random.seed is created (or modified) eval(rand_seed) } \references{ diff --git a/man/raw_block.Rd b/man/raw_block.Rd index 6ece27320b..fa128f402e 100644 --- a/man/raw_block.Rd +++ b/man/raw_block.Rd @@ -29,5 +29,5 @@ Functions \code{raw_latex()} and \code{raw_html()} are shorthands of \code{raw_block(x, 'latex')} and \code{raw_block(x, 'html')}, respectively. } \examples{ -knitr::raw_latex("\\\\emph{some text}") +knitr::raw_latex('\\\\emph{some text}') } diff --git a/man/raw_output.Rd b/man/raw_output.Rd index eeb7b6279b..7269e29e9d 100644 --- a/man/raw_output.Rd +++ b/man/raw_output.Rd @@ -52,14 +52,11 @@ output. } \examples{ library(knitr) -out = c("*hello*", raw_output("content *protect* me!"), - "*world*") +out = c('*hello*', raw_output('content *protect* me!'), '*world*') pre = extract_raw_output(out) str(pre) -pre$value = gsub("[*]([^*]+)[*]", "\\\\1", - pre$value) # think this as Pandoc conversion +pre$value = gsub('[*]([^*]+)[*]', '\\\\1', pre$value) # think this as Pandoc conversion pre$value -# raw output was protected from the conversion (e.g. -# *protect* was not converted) +# raw output was protected from the conversion (e.g. *protect* was not converted) restore_raw_output(pre$value, pre$chunks) } diff --git a/man/read_chunk.Rd b/man/read_chunk.Rd index c9116542a6..2cb6654223 100644 --- a/man/read_chunk.Rd +++ b/man/read_chunk.Rd @@ -80,25 +80,24 @@ This function can only be used in a chunk which is \emph{not} cached ## put this in foo.R and read_chunk('foo.R') ## ---- my-label ---- -1 + 1 -lm(y ~ x, data = data.frame(x = 1:10, y = rnorm(10))) +1+1 +lm(y~x, data=data.frame(x=1:10,y=rnorm(10))) ## later you can use <>= to reference this chunk ## the 2nd approach -code = c("#@a", "1+1", "#@b", "#@a", "rnorm(10)", "#@b") -read_chunk(lines = code, labels = "foo") # put all code into one chunk named foo -read_chunk(lines = code, labels = "foo", from = 2, to = 2) # line 2 into chunk foo -read_chunk(lines = code, labels = c("foo", "bar"), from = c(1, 4), to = c(3, 6)) +code = c("#@a", '1+1', "#@b", "#@a", 'rnorm(10)', "#@b") +read_chunk(lines = code, labels = 'foo') # put all code into one chunk named foo +read_chunk(lines = code, labels = 'foo', from = 2, to = 2) # line 2 into chunk foo +read_chunk(lines = code, labels = c('foo', 'bar'), from = c(1, 4), to = c(3, 6)) # automatically figure out 'to' -read_chunk(lines = code, labels = c("foo", "bar"), from = c(1, 4)) -read_chunk(lines = code, labels = c("foo", "bar"), from = "^#@a", to = "^#@b") -read_chunk(lines = code, labels = c("foo", "bar"), from = "^#@a", to = "^#@b", - from.offset = 1, to.offset = -1) +read_chunk(lines = code, labels = c('foo', 'bar'), from = c(1, 4)) +read_chunk(lines = code, labels = c('foo', 'bar'), from = "^#@a", to = "^#@b") +read_chunk(lines = code, labels = c('foo', 'bar'), from = "^#@a", to = "^#@b", from.offset = 1, to.offset = -1) ## later you can use, e.g., <>= -knitr:::knit_code$get() # use this to check chunks in the current session -knitr:::knit_code$restore() # clean up the session +knitr:::knit_code$get() # use this to check chunks in the current session +knitr:::knit_code$restore() # clean up the session } \references{ \url{https://yihui.org/knitr/demo/externalization/} diff --git a/man/read_rforge.Rd b/man/read_rforge.Rd index 3450415e15..758c1e66cb 100644 --- a/man/read_rforge.Rd +++ b/man/read_rforge.Rd @@ -22,11 +22,9 @@ This function reads source code from the SVN repositories on R-Forge. } \examples{ library(knitr) -\donttest{ -# relies on r-forge.r-project.org being accessible -read_rforge("rgl/R/axes.R", project = "rgl") -read_rforge("rgl/R/axes.R", project = "rgl", extra = "&revision=519") -} +\donttest{# relies on r-forge.r-project.org being accessible +read_rforge('rgl/R/axes.R', project = 'rgl') +read_rforge('rgl/R/axes.R', project = 'rgl', extra='&revision=519')} } \author{ Yihui Xie and Peter Ruckdeschel diff --git a/man/rocco.Rd b/man/rocco.Rd index aa9b6dcf13..4c15c18412 100644 --- a/man/rocco.Rd +++ b/man/rocco.Rd @@ -26,18 +26,14 @@ the key \code{t} to hide the code column (show the text column only), and press again to hide the text column (show code). } \examples{ -rocco_view = function(input) { - owd = setwd(tempdir()) - on.exit(setwd(owd)) - if (!file.exists(input)) - return() - o = rocco(input, header = "", quiet = TRUE) - if (interactive()) - browseURL(o) -} +rocco_view=function(input) { +owd = setwd(tempdir()); on.exit(setwd(owd)) +if (!file.exists(input)) return() +o=rocco(input, header='', quiet=TRUE) +if (interactive()) browseURL(o)} # knit these two vignettes using the docco style -rocco_view(system.file("doc", "docco-classic.Rmd", package = "knitr")) -rocco_view(system.file("doc", "knit_expand.Rmd", package = "knitr")) +rocco_view(system.file('doc', 'docco-classic.Rmd', package = 'knitr')) +rocco_view(system.file('doc', 'knit_expand.Rmd', package = 'knitr')) } \references{ The Docco package by Jeremy Ashkenas: diff --git a/man/set_alias.Rd b/man/set_alias.Rd index ef58a359dc..b8afa52a4b 100644 --- a/man/set_alias.Rd +++ b/man/set_alias.Rd @@ -19,7 +19,6 @@ 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. } \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 +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 } diff --git a/man/set_header.Rd b/man/set_header.Rd index da39246454..b24f7ea820 100644 --- a/man/set_header.Rd +++ b/man/set_header.Rd @@ -39,6 +39,6 @@ definitions of the \pkg{listings} package (and modify the output hooks accordingly), so we can decorate R code using the \pkg{listings} package. } \examples{ -set_header(tikz = "\\\\usepackage{tikz}") -opts_knit$get("header") +set_header(tikz = '\\\\usepackage{tikz}') +opts_knit$get('header') } diff --git a/man/stitch.Rd b/man/stitch.Rd index 8ccb207fe5..53f557a177 100644 --- a/man/stitch.Rd +++ b/man/stitch.Rd @@ -57,16 +57,16 @@ headers are found, the whole R script will be inserted into the template as one code chunk. } \examples{ -s = system.file("misc", "stitch-test.R", package = "knitr") +s = system.file('misc', 'stitch-test.R', package = 'knitr') if (interactive()) stitch(s) # compile to PDF # HTML report -stitch(s, system.file("misc", "knitr-template.Rhtml", package = "knitr")) +stitch(s, system.file('misc', 'knitr-template.Rhtml', package = 'knitr')) # or convert markdown to HTML -stitch(s, system.file("misc", "knitr-template.Rmd", package = "knitr")) +stitch(s, system.file('misc', 'knitr-template.Rmd', package = 'knitr')) -unlink(c("stitch-test.html", "stitch-test.md", "figure"), recursive = TRUE) +unlink(c('stitch-test.html', 'stitch-test.md', 'figure'), recursive = TRUE) } \seealso{ \code{\link{spin}} (turn a specially formatted R script to a report) diff --git a/man/vignette_engines.Rd b/man/vignette_engines.Rd index 5883ba761b..ad40965402 100644 --- a/man/vignette_engines.Rd +++ b/man/vignette_engines.Rd @@ -30,9 +30,9 @@ If you use the \code{knitr::rmarkdown} engine, please make sure that } \examples{ library(knitr) -vig_list = tools::vignetteEngine(package = "knitr") +vig_list = tools::vignetteEngine(package = 'knitr') str(vig_list) -vig_list[["knitr::knitr"]][c("weave", "tangle")] -vig_list[["knitr::knitr_notangle"]][c("weave", "tangle")] -vig_list[["knitr::docco_classic"]][c("weave", "tangle")] +vig_list[['knitr::knitr']][c('weave', 'tangle')] +vig_list[['knitr::knitr_notangle']][c('weave', 'tangle')] +vig_list[['knitr::docco_classic']][c('weave', 'tangle')] } diff --git a/man/wrap_rmd.Rd b/man/wrap_rmd.Rd index 2418476253..6f377cdece 100644 --- a/man/wrap_rmd.Rd +++ b/man/wrap_rmd.Rd @@ -33,6 +33,6 @@ Currently it does not wrap blockquotes or lists (ordered or unordered). This feature may or may not be added in the future. } \examples{ -wrap_rmd(text = c("```", "1+1", "```", "- a list item", "> a quote", "", - paste(rep("this is a normal paragraph", 5), collapse = " "))) +wrap_rmd(text = c('```', '1+1', '```', '- a list item', '> a quote', '', +paste(rep('this is a normal paragraph', 5), collapse = ' '))) } diff --git a/man/write_bib.Rd b/man/write_bib.Rd index a32811f2f8..e093991fe6 100644 --- a/man/write_bib.Rd +++ b/man/write_bib.Rd @@ -70,14 +70,14 @@ Some packages on CRAN do not have standard bib entries, which was once \file{inst/misc/tweak_bib.csv} in the source package. } \examples{ -write_bib(c("RGtk2", "gWidgets"), file = "R-GUI-pkgs.bib") -unlink("R-GUI-pkgs.bib") +write_bib(c('RGtk2', 'gWidgets'), file = 'R-GUI-pkgs.bib') +unlink('R-GUI-pkgs.bib') -write_bib(c("animation", "rgl", "knitr", "ggplot2")) -write_bib(c("base", "parallel", "MASS")) # base and parallel are identical -write_bib("cluster", prefix = "") # a empty prefix -write_bib("digest", prefix = "R-pkg-") # a new prefix -write_bib("digest", tweak = FALSE) # original version +write_bib(c('animation', 'rgl', 'knitr', 'ggplot2')) +write_bib(c('base', 'parallel', 'MASS')) # base and parallel are identical +write_bib('cluster', prefix = '') # a empty prefix +write_bib('digest', prefix = 'R-pkg-') # a new prefix +write_bib('digest', tweak = FALSE) # original version # what tweak=TRUE does str(knitr:::.tweak.bib) From 5cdc625eed84200331b5c6e04f8db58919abccb7 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Sun, 13 Dec 2020 14:34:01 -0600 Subject: [PATCH 02/15] updated namespace --- NAMESPACE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 53867ee569..4a6a1ac306 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,6 +26,8 @@ export(all_labels) export(all_patterns) export(all_rcpp_labels) export(asis_output) +export(block_exec) +export(block_exec_R) export(cache_engines) export(clean_cache) export(combine_words) From e2c6a5a7afa05cef840638e8c029ca1fd08d5577 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Tue, 9 Feb 2021 22:23:52 -0600 Subject: [PATCH 03/15] eng_r added --- NAMESPACE | 3 +-- R/block.R | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 4a6a1ac306..ef6622a5ca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,14 +26,13 @@ export(all_labels) export(all_patterns) export(all_rcpp_labels) export(asis_output) -export(block_exec) -export(block_exec_R) export(cache_engines) export(clean_cache) export(combine_words) export(current_input) export(dep_auto) export(dep_prev) +export(eng_r) export(engine_output) export(extract_raw_output) export(fig_chunk) diff --git a/R/block.R b/R/block.R index f86fc69f07..6de36bde80 100644 --- a/R/block.R +++ b/R/block.R @@ -100,7 +100,6 @@ cache2.opts = c('fig.keep', 'fig.path', 'fig.ext', 'dev', 'dpi', 'dev.args', 'fi # options that should not affect cache cache0.opts = c('include', 'out.width.px', 'out.height.px', 'cache.rebuild') -#' @export block_exec = function(options) { # when code is not R language if (options$engine != 'R') { @@ -119,13 +118,26 @@ block_exec = function(options) { )) } return(if (options$include) output else '') - } else if (options$engine == "R") { - block_exec_R(options) + } else { + eng_r(options) } } +#' Engine for R +#' +#' This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) +#' and generates the R output for each code block. +#' +#' This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. +#' It returns a processed output which can consist of data frames (as tables), graphs or character output. +#' This function is intended for advanced use to allow developers to extend R, +#' and customise the pipeline with which R code is executed and processed within knitr. +#' +#' @param options A list of chunk options. Usually this is just the object +#' \code{options} associated with the current code chunk. +#' #' @export -block_exec_R = function(options) { +eng_r = function(options) { # eval chunks (in an empty envir if cache) env = knit_global() obj.before = ls(globalenv(), all.names = TRUE) # global objects before chunk From d47a66711a9f00e15a8e6f85fcac37a35c9c9007 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Wed, 10 Feb 2021 13:28:14 -0600 Subject: [PATCH 04/15] documentation eng_r --- R/block.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/block.R b/R/block.R index 6de36bde80..d53caa9581 100644 --- a/R/block.R +++ b/R/block.R @@ -123,6 +123,7 @@ block_exec = function(options) { } } + #' Engine for R #' #' This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) @@ -135,7 +136,7 @@ block_exec = function(options) { #' #' @param options A list of chunk options. Usually this is just the object #' \code{options} associated with the current code chunk. -#' + #' @export eng_r = function(options) { # eval chunks (in an empty envir if cache) From 16b4f89e05aa2c35781b9e6f565dd22ff9751473 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Wed, 10 Feb 2021 13:30:28 -0600 Subject: [PATCH 05/15] documentation eng_r --- man/eng_r.Rd | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 man/eng_r.Rd diff --git a/man/eng_r.Rd b/man/eng_r.Rd new file mode 100644 index 0000000000..0fb5e4a62b --- /dev/null +++ b/man/eng_r.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/block.R +\name{eng_r} +\alias{eng_r} +\title{Engine for R} +\usage{ +eng_r(options) +} +\arguments{ +\item{options}{A list of chunk options. Usually this is just the object +\code{options} associated with the current code chunk.} +} +\description{ +This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) +and generates the R output for each code block. +} +\details{ +This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. +It returns a processed output which can consist of data frames (as tables), graphs or character output. +This function is intended for advanced use to allow developers to extend R, +and customise the pipeline with which R code is executed and processed within knitr. +} From 4b9b7891806f7e7cbe99e11f56697423a7e903ae Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Thu, 11 Feb 2021 21:28:34 -0600 Subject: [PATCH 06/15] added eng_r --- R/block.R | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/R/block.R b/R/block.R index d57d4b3792..f0b2aba1b0 100644 --- a/R/block.R +++ b/R/block.R @@ -115,11 +115,30 @@ block_exec = function(options) { if (options$cache.rebuild || !cache.exists) block_cache(options, output, switch( options$engine, 'stan' = options$output.var, 'sql' = options$output.var, character(0) - )) - } + )) + } return(if (options$include) output else '') + } else { + eng_r(options) } +} + +#' Engine for R +#' +#' This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) +#' and generates the R output for each code block. +#' +#' This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. +#' It returns a processed output which can consist of data frames (as tables), graphs or character output. +#' This function is intended for advanced use to allow developers to extend R, +#' and customise the pipeline with which R code is executed and processed within knitr. +#' +#' @param options A list of chunk options. Usually this is just the object +#' \code{options} associated with the current code chunk. + +#' @export +eng_r = function(options) { # eval chunks (in an empty envir if cache) env = knit_global() obj.before = ls(globalenv(), all.names = TRUE) # global objects before chunk From 73401aa44219afd23aa46a869e948024b4a5f6a1 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Thu, 11 Feb 2021 21:30:26 -0600 Subject: [PATCH 07/15] updated NAMESPACE --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 53867ee569..ef6622a5ca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ export(combine_words) export(current_input) export(dep_auto) export(dep_prev) +export(eng_r) export(engine_output) export(extract_raw_output) export(fig_chunk) From 2792e6e821bd2c86c2d7b847a4a9c0adbf7a6dc8 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Thu, 11 Feb 2021 21:41:57 -0600 Subject: [PATCH 08/15] documentation eng_r --- man/eng_r.Rd | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 man/eng_r.Rd diff --git a/man/eng_r.Rd b/man/eng_r.Rd new file mode 100644 index 0000000000..0fb5e4a62b --- /dev/null +++ b/man/eng_r.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/block.R +\name{eng_r} +\alias{eng_r} +\title{Engine for R} +\usage{ +eng_r(options) +} +\arguments{ +\item{options}{A list of chunk options. Usually this is just the object +\code{options} associated with the current code chunk.} +} +\description{ +This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) +and generates the R output for each code block. +} +\details{ +This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. +It returns a processed output which can consist of data frames (as tables), graphs or character output. +This function is intended for advanced use to allow developers to extend R, +and customise the pipeline with which R code is executed and processed within knitr. +} From 2d65be02a20cea4bfe762b4413a75bcab0d51f37 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Fri, 12 Feb 2021 12:11:27 -0600 Subject: [PATCH 09/15] allow set engine R --- NAMESPACE | 1 - R/block.R | 3 +-- R/engine.R | 2 +- man/eng_r.Rd | 22 ---------------------- 4 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 man/eng_r.Rd diff --git a/NAMESPACE b/NAMESPACE index ef6622a5ca..53867ee569 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,7 +32,6 @@ export(combine_words) export(current_input) export(dep_auto) export(dep_prev) -export(eng_r) export(engine_output) export(extract_raw_output) export(fig_chunk) diff --git a/R/block.R b/R/block.R index d53caa9581..453ebd09fe 100644 --- a/R/block.R +++ b/R/block.R @@ -136,8 +136,7 @@ block_exec = function(options) { #' #' @param options A list of chunk options. Usually this is just the object #' \code{options} associated with the current code chunk. - -#' @export +#' eng_r = function(options) { # eval chunks (in an empty envir if cache) env = knit_global() diff --git a/R/engine.R b/R/engine.R index c66e587d06..41d5516700 100644 --- a/R/engine.R +++ b/R/engine.R @@ -756,7 +756,7 @@ knit_engines$set( c = eng_shlib, cc = 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, - python = eng_python, julia = eng_julia, sass = eng_sxss, scss = eng_sxss + python = eng_python, julia = eng_julia, sass = eng_sxss, scss = eng_sxss, R = eng_r ) cache_engines$set(python = cache_eng_python) diff --git a/man/eng_r.Rd b/man/eng_r.Rd deleted file mode 100644 index 0fb5e4a62b..0000000000 --- a/man/eng_r.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/block.R -\name{eng_r} -\alias{eng_r} -\title{Engine for R} -\usage{ -eng_r(options) -} -\arguments{ -\item{options}{A list of chunk options. Usually this is just the object -\code{options} associated with the current code chunk.} -} -\description{ -This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) -and generates the R output for each code block. -} -\details{ -This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. -It returns a processed output which can consist of data frames (as tables), graphs or character output. -This function is intended for advanced use to allow developers to extend R, -and customise the pipeline with which R code is executed and processed within knitr. -} From 2cac905e1f65da80cf55a8e11c0c754aae9c20e5 Mon Sep 17 00:00:00 2001 From: Abhraneel Sarma Date: Fri, 12 Feb 2021 12:19:13 -0600 Subject: [PATCH 10/15] removed exported eng_r --- NAMESPACE | 1 - R/block.R | 6 ------ man/eng_r.Rd | 22 ---------------------- 3 files changed, 29 deletions(-) delete mode 100644 man/eng_r.Rd diff --git a/NAMESPACE b/NAMESPACE index ef6622a5ca..53867ee569 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,7 +32,6 @@ export(combine_words) export(current_input) export(dep_auto) export(dep_prev) -export(eng_r) export(engine_output) export(extract_raw_output) export(fig_chunk) diff --git a/R/block.R b/R/block.R index 90511f22e5..9ada2f5ec4 100644 --- a/R/block.R +++ b/R/block.R @@ -122,13 +122,7 @@ block_exec = function(options) { eng_r(options) } } -<<<<<<< HEAD - -======= - - ->>>>>>> 2792e6e821bd2c86c2d7b847a4a9c0adbf7a6dc8 #' Engine for R #' #' This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) diff --git a/man/eng_r.Rd b/man/eng_r.Rd deleted file mode 100644 index 0fb5e4a62b..0000000000 --- a/man/eng_r.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/block.R -\name{eng_r} -\alias{eng_r} -\title{Engine for R} -\usage{ -eng_r(options) -} -\arguments{ -\item{options}{A list of chunk options. Usually this is just the object -\code{options} associated with the current code chunk.} -} -\description{ -This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) -and generates the R output for each code block. -} -\details{ -This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. -It returns a processed output which can consist of data frames (as tables), graphs or character output. -This function is intended for advanced use to allow developers to extend R, -and customise the pipeline with which R code is executed and processed within knitr. -} From 78824737a4a7af831ea3f0111f02b842a37327dc Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 11 Mar 2021 13:23:25 -0600 Subject: [PATCH 11/15] return early if the engine is R --- R/block.R | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/R/block.R b/R/block.R index 9ada2f5ec4..8210ab3673 100644 --- a/R/block.R +++ b/R/block.R @@ -101,26 +101,24 @@ cache2.opts = c('fig.keep', 'fig.path', 'fig.ext', 'dev', 'dpi', 'dev.args', 'fi cache0.opts = c('include', 'out.width.px', 'out.height.px', 'cache.rebuild') block_exec = function(options) { + if (options$engine == 'R') return(eng_r(options)) + # when code is not R language - if (options$engine != 'R') { - 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) - if (options$cache) { - cache.exists = cache$exists(options$hash, options$cache.lazy) - if (options$cache.rebuild || !cache.exists) block_cache(options, output, switch( - options$engine, - 'stan' = options$output.var, 'sql' = options$output.var, character(0) - )) - } - return(if (options$include) output else '') - } else { - eng_r(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) + if (options$cache) { + cache.exists = cache$exists(options$hash, options$cache.lazy) + if (options$cache.rebuild || !cache.exists) block_cache(options, output, switch( + options$engine, + 'stan' = options$output.var, 'sql' = options$output.var, character(0) + )) } + if (options$include) output else '' } #' Engine for R From c8c530c397b8e04a64e77010da88606c5e252f5f Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 11 Mar 2021 13:25:36 -0600 Subject: [PATCH 12/15] rewrap roxygen comments --- R/block.R | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/R/block.R b/R/block.R index 8210ab3673..c0e66a47f2 100644 --- a/R/block.R +++ b/R/block.R @@ -123,17 +123,19 @@ block_exec = function(options) { #' Engine for R #' -#' This function handles the execution of R code blocks (when the chunk option \code{engine} is \code{'R'}) -#' and generates the R output for each code block. +#' This function handles the execution of R code blocks (when the chunk option +#' \code{engine} is \code{'R'}) and generates the R output for each code block. #' -#' This engine function has one argument \code{options}: the source code of the current chunk is in \code{options$code}. -#' It returns a processed output which can consist of data frames (as tables), graphs or character output. -#' This function is intended for advanced use to allow developers to extend R, -#' and customise the pipeline with which R code is executed and processed within knitr. +#' This engine function has one argument \code{options}: the source code of the +#' current chunk is in \code{options$code}. It returns a processed output that +#' can consist of data frames (as tables), graphs, or character output. This +#' function is intended for advanced use to allow developers to extend R, and +#' customize the pipeline with which R code is executed and processed within +#' knitr. #' #' @param options A list of chunk options. Usually this is just the object #' \code{options} associated with the current code chunk. -#' +#' @noRd eng_r = function(options) { # eval chunks (in an empty envir if cache) env = knit_global() From a6a10f14cdcf2fe9c2abef9184ffe5c93fdeb323 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 11 Mar 2021 13:26:00 -0600 Subject: [PATCH 13/15] revert changes in .Rd --- man/Sweave2knitr.Rd | 18 ++++++++--------- man/all_labels.Rd | 6 +++--- man/all_patterns.Rd | 3 ++- man/asis_output.Rd | 2 +- man/chunk_hook.Rd | 2 +- man/combine_words.Rd | 11 ++++++----- man/engine_output.Rd | 10 +++++++--- man/fig_chunk.Rd | 8 ++++---- man/fig_path.Rd | 4 ++-- man/hook_document.Rd | 4 +++- man/hook_plot.Rd | 7 ++++--- man/image_uri.Rd | 7 ++++--- man/imgur_upload.Rd | 13 +++++++----- man/inline_expr.Rd | 4 +++- man/kable.Rd | 44 +++++++++++++++++++++-------------------- man/knit.Rd | 4 ++-- man/knit2html.Rd | 9 +++++---- man/knit_child.Rd | 4 ++-- man/knit_engines.Rd | 3 ++- man/knit_expand.Rd | 2 +- man/knit_filter.Rd | 15 +++++++------- man/knit_hooks.Rd | 3 ++- man/knit_patterns.Rd | 8 ++++---- man/knit_print.Rd | 8 ++++---- man/knit_rd.Rd | 8 ++++---- man/knit_theme.Rd | 7 ++++--- man/opts_chunk.Rd | 3 ++- man/opts_hooks.Rd | 8 ++++---- man/opts_knit.Rd | 9 +++++---- man/output_type.Rd | 2 +- man/pandoc.Rd | 2 +- man/pat_fun.Rd | 4 +++- man/rand_seed.Rd | 2 +- man/raw_block.Rd | 2 +- man/raw_output.Rd | 9 ++++++--- man/read_chunk.Rd | 23 ++++++++++----------- man/read_rforge.Rd | 8 +++++--- man/rocco.Rd | 18 ++++++++++------- man/set_alias.Rd | 5 +++-- man/set_header.Rd | 4 ++-- man/stitch.Rd | 8 ++++---- man/vignette_engines.Rd | 8 ++++---- man/wrap_rmd.Rd | 4 ++-- man/write_bib.Rd | 14 ++++++------- 44 files changed, 192 insertions(+), 155 deletions(-) diff --git a/man/Sweave2knitr.Rd b/man/Sweave2knitr.Rd index 2becef3825..657ed1c40e 100644 --- a/man/Sweave2knitr.Rd +++ b/man/Sweave2knitr.Rd @@ -68,17 +68,17 @@ If \samp{\\SweaveOpts{}} spans across multiple lines, it will not be is supported. } \examples{ -Sweave2knitr(text='<>=') # this is valid -Sweave2knitr(text="<>=") # dev='png' -Sweave2knitr(text="<>=") -Sweave2knitr(text="<<,png=false,fig=TRUE>>=") -Sweave2knitr(text="\\\\SweaveOpts{echo=false}") -Sweave2knitr(text="\\\\SweaveInput{hello.Rnw}") +Sweave2knitr(text = "<>=") # this is valid +Sweave2knitr(text = "<>=") # dev='png' +Sweave2knitr(text = "<>=") +Sweave2knitr(text = "<<,png=false,fig=TRUE>>=") +Sweave2knitr(text = "\\\\SweaveOpts{echo=false}") +Sweave2knitr(text = "\\\\SweaveInput{hello.Rnw}") # Sweave example in utils testfile = system.file("Sweave", "Sweave-test-1.Rnw", package = "utils") -Sweave2knitr(testfile, output = 'Sweave-test-knitr.Rnw') -if (interactive()) knit('Sweave-test-knitr.Rnw') # or knit2pdf() directly -unlink('Sweave-test-knitr.Rnw') +Sweave2knitr(testfile, output = "Sweave-test-knitr.Rnw") +if (interactive()) knit("Sweave-test-knitr.Rnw") # or knit2pdf() directly +unlink("Sweave-test-knitr.Rnw") } \references{ The motivation of the changes in the syntax: diff --git a/man/all_labels.Rd b/man/all_labels.Rd index 914b3ec19b..aca44d1c38 100644 --- a/man/all_labels.Rd +++ b/man/all_labels.Rd @@ -42,8 +42,8 @@ Empty code chunks are always ignored, including those chunks that are \examples{ # the examples below are meaningless unless you put them in a knitr document all_labels() -all_labels(engine == 'Rcpp') -all_labels(echo == FALSE && results != 'hide') +all_labels(engine == "Rcpp") +all_labels(echo == FALSE && results != "hide") # or separate the two conditions -all_labels(echo == FALSE, results != 'hide') +all_labels(echo == FALSE, results != "hide") } diff --git a/man/all_patterns.Rd b/man/all_patterns.Rd index 811139e87a..4bd133e680 100644 --- a/man/all_patterns.Rd +++ b/man/all_patterns.Rd @@ -14,7 +14,8 @@ all_patterns This object is a named list of all built-in patterns. } \examples{ -all_patterns$rnw; all_patterns$html +all_patterns$rnw +all_patterns$html str(all_patterns) } diff --git a/man/asis_output.Rd b/man/asis_output.Rd index 9e6dffb240..a96db47c49 100644 --- a/man/asis_output.Rd +++ b/man/asis_output.Rd @@ -48,5 +48,5 @@ This function only works in top-level R expressions, and it will not \url{https://github.com/yihui/knitr/issues/1137} for a discussion. } \examples{ - # see ?knit_print +# see ?knit_print } diff --git a/man/chunk_hook.Rd b/man/chunk_hook.Rd index 8d01f7702a..8938b7f685 100644 --- a/man/chunk_hook.Rd +++ b/man/chunk_hook.Rd @@ -75,7 +75,7 @@ The two hook functions \code{hook_rgl()} and \code{hook_webgl()} were \pkg{knitr} v1.10.5, and you can \code{library(rgl)} to get them. } \examples{ -if (require('rgl') && exists('hook_rgl')) knit_hooks$set(rgl = hook_rgl) +if (require("rgl") && exists("hook_rgl")) knit_hooks$set(rgl = hook_rgl) # then in code chunks, use the option rgl=TRUE } \references{ diff --git a/man/combine_words.Rd b/man/combine_words.Rd index e4faca80bd..f02a8df3a8 100644 --- a/man/combine_words.Rd +++ b/man/combine_words.Rd @@ -31,9 +31,10 @@ greater than 2, \code{sep} is used to separate all words, and the \code{and} string is prepended to the last word. } \examples{ -combine_words('a'); combine_words(c('a', 'b')) -combine_words(c('a', 'b', 'c')) -combine_words(c('a', 'b', 'c'), sep = ' / ', and = '') -combine_words(c('a', 'b', 'c'), and = '') -combine_words(c('a', 'b', 'c'), before = '"', after = '"') +combine_words("a") +combine_words(c("a", "b")) +combine_words(c("a", "b", "c")) +combine_words(c("a", "b", "c"), sep = " / ", and = "") +combine_words(c("a", "b", "c"), and = "") +combine_words(c("a", "b", "c"), before = "\"", after = "\"") } diff --git a/man/engine_output.Rd b/man/engine_output.Rd index 2d8a957609..aaaa02acdf 100644 --- a/man/engine_output.Rd +++ b/man/engine_output.Rd @@ -37,9 +37,13 @@ vector of final output. } \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') +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(opts_chunk$merge(list(engine = "python")), + out = list(structure(list(src = "1 + 1"), class = "source"), + "2")) } diff --git a/man/fig_chunk.Rd b/man/fig_chunk.Rd index ca2d6b89c7..97e088f751 100644 --- a/man/fig_chunk.Rd +++ b/man/fig_chunk.Rd @@ -39,8 +39,8 @@ this function if you want to show them elsewhere. } \examples{ library(knitr) -fig_chunk('foo', 'png') -fig_chunk('foo', 'pdf') -fig_chunk('foo', 'svg', 2) # the second plot of the chunk foo -fig_chunk('foo', 'png', 1:5) # if the chunk foo produced 5 plots +fig_chunk("foo", "png") +fig_chunk("foo", "pdf") +fig_chunk("foo", "svg", 2) # the second plot of the chunk foo +fig_chunk("foo", "png", 1:5) # if the chunk foo produced 5 plots } diff --git a/man/fig_path.Rd b/man/fig_path.Rd index 0bb84749f3..ebb4623637 100644 --- a/man/fig_path.Rd +++ b/man/fig_path.Rd @@ -31,6 +31,6 @@ When there are special characters (not alphanumeric or \samp{-} or makes the filenames safe to LaTeX. } \examples{ -fig_path('.pdf', options = list(fig.path='figure/abc-', label='first-plot')) -fig_path('.png', list(fig.path='foo-', label='bar'), 1:10) +fig_path(".pdf", options = list(fig.path = "figure/abc-", label = "first-plot")) +fig_path(".png", list(fig.path = "foo-", label = "bar"), 1:10) } diff --git a/man/hook_document.Rd b/man/hook_document.Rd index f164c2603d..60cc6dcb00 100644 --- a/man/hook_document.Rd +++ b/man/hook_document.Rd @@ -32,7 +32,9 @@ These functions are hackish. Also note \code{hook_movecode()} assumes every figure/table environment must have a label. } \examples{ -\dontrun{knit_hooks$set(document = hook_movecode)} +\dontrun{ +knit_hooks$set(document = hook_movecode) +} # see example 103 at https://github.com/yihui/knitr-examples } \references{ diff --git a/man/hook_plot.Rd b/man/hook_plot.Rd index 19dc7c49c6..ed48320c42 100644 --- a/man/hook_plot.Rd +++ b/man/hook_plot.Rd @@ -53,15 +53,16 @@ these hooks to insert graphics output in the output document; see # this is what happens for a chunk like this # <>= -hook_plot_tex('foo-bar-plot.pdf', opts_chunk$merge(list(fig.align='right'))) +hook_plot_tex("foo-bar-plot.pdf", opts_chunk$merge(list(fig.align = "right"))) # <>= -hook_plot_tex('bar.tikz', opts_chunk$merge(list(dev='tikz'))) +hook_plot_tex("bar.tikz", opts_chunk$merge(list(dev = "tikz"))) # <>= # 5 plots are generated in this chunk -hook_plot_tex('foo5.pdf', opts_chunk$merge(list(fig.show='animate',interval=.1,fig.cur=5, fig.num=5))) +hook_plot_tex("foo5.pdf", opts_chunk$merge(list(fig.show = "animate", interval = 0.1, + fig.cur = 5, fig.num = 5))) } \references{ \url{https://yihui.org/knitr/hooks/} diff --git a/man/image_uri.Rd b/man/image_uri.Rd index b8d6a0e0f5..25ec53d4ed 100644 --- a/man/image_uri.Rd +++ b/man/image_uri.Rd @@ -18,9 +18,10 @@ different function name). It can encode an image file as a base64 string, which can be used in the \code{img} tag in HTML. } \examples{ -uri = image_uri(file.path(R.home('doc'), 'html', 'logo.jpg')) -if (interactive()) {cat(sprintf('', uri), file = 'logo.html') -browseURL('logo.html') # you can check its HTML source +uri = image_uri(file.path(R.home("doc"), "html", "logo.jpg")) +if (interactive()) { + cat(sprintf("", uri), file = "logo.html") + browseURL("logo.html") # you can check its HTML source } } \references{ diff --git a/man/imgur_upload.Rd b/man/imgur_upload.Rd index f6b9496df3..b7477d5f90 100644 --- a/man/imgur_upload.Rd +++ b/man/imgur_upload.Rd @@ -36,16 +36,19 @@ Please register your own Imgur application to get your client ID; you } \examples{ \dontrun{ -f = tempfile(fileext = '.png') -png(f); plot(rnorm(100), main = R.version.string); dev.off() +f = tempfile(fileext = ".png") +png(f) +plot(rnorm(100), main = R.version.string) +dev.off() res = imgur_upload(f) res # link to original URL of the image -attr(res, 'XML') # all information -if (interactive()) browseURL(res) +attr(res, "XML") # all information +if (interactive()) + browseURL(res) # to use your own key -opts_knit$set(upload.fun = function(file) imgur_upload(file, key = 'your imgur key')) +opts_knit$set(upload.fun = function(file) imgur_upload(file, key = "your imgur key")) } } \references{ diff --git a/man/inline_expr.Rd b/man/inline_expr.Rd index f6c194034f..dedce8cfc7 100644 --- a/man/inline_expr.Rd +++ b/man/inline_expr.Rd @@ -25,5 +25,7 @@ R Markdown document, you may write \samp{`` `r knitr::inline_expr('1+1')` } \examples{ library(knitr) -inline_expr('1+1', 'rnw'); inline_expr('1+1', 'html'); inline_expr('1+1', 'md') +inline_expr("1+1", "rnw") +inline_expr("1+1", "html") +inline_expr("1+1", "md") } diff --git a/man/kable.Rd b/man/kable.Rd index ed9367c139..ee2099d4bb 100644 --- a/man/kable.Rd +++ b/man/kable.Rd @@ -90,43 +90,45 @@ When using \code{kable()} as a \emph{top-level} expression, you do not \code{\link{for}} loop), you must explicitly \code{print(kable(...))}. } \examples{ -d1 = head(iris); d2 = head(mtcars) +d1 = head(iris) +d2 = head(mtcars) # pipe tables by default kable(d1) kable(d2[, 1:5]) # no inner padding -kable(d2, format = 'pipe', padding = 0) +kable(d2, format = "pipe", padding = 0) # more padding -kable(d2, format = 'pipe', padding = 2) -kable(d1, format = 'latex') -kable(d1, format = 'html') -kable(d1, format = 'latex', caption = 'Title of the table') -kable(d1, format = 'html', caption = 'Title of the table') +kable(d2, format = "pipe", padding = 2) +kable(d1, format = "latex") +kable(d1, format = "html") +kable(d1, format = "latex", caption = "Title of the table") +kable(d1, format = "html", caption = "Title of the table") # use the booktabs package -kable(mtcars, format = 'latex', booktabs = TRUE) +kable(mtcars, format = "latex", booktabs = TRUE) # use the longtable package -kable(matrix(1000, ncol=5), format = 'latex', digits = 2, longtable = TRUE) +kable(matrix(1000, ncol = 5), format = "latex", digits = 2, longtable = TRUE) # change LaTeX default table environment -kable(d1, format = "latex", caption = "My table", table.envir='table*') +kable(d1, format = "latex", caption = "My table", table.envir = "table*") # add some table attributes -kable(d1, format = 'html', table.attr = 'id="mytable"') +kable(d1, format = "html", table.attr = "id=\"mytable\"") # reST output -kable(d2, format = 'rst') +kable(d2, format = "rst") # no row names -kable(d2, format = 'rst', row.names = FALSE) +kable(d2, format = "rst", row.names = FALSE) # Pandoc simple tables -kable(d2, format = 'simple', caption = 'Title of the table') +kable(d2, format = "simple", caption = "Title of the table") # format numbers using , as decimal point, and ' as thousands separator -x = as.data.frame(matrix(rnorm(60, 1e6, 1e4), 10)) -kable(x, format.args = list(decimal.mark = ',', big.mark = "'")) +x = as.data.frame(matrix(rnorm(60, 1e+06, 10000), 10)) +kable(x, format.args = list(decimal.mark = ",", big.mark = "'")) # save the value -x = kable(d2, format = 'html') -cat(x, sep = '\n') +x = kable(d2, format = "html") +cat(x, sep = "\n") # can also set options(knitr.table.format = 'html') so that the output is HTML -# multiple tables via either kable(list(x1, x2)) or kables(list(kable(x1), kable(x2))) -kable(list(d1, d2), caption = 'A tale of two tables') -kables(list(kable(d1, align = 'l'), kable(d2)), caption = 'A tale of two tables') +# multiple tables via either kable(list(x1, x2)) or kables(list(kable(x1), +# kable(x2))) +kable(list(d1, d2), caption = "A tale of two tables") +kables(list(kable(d1, align = "l"), kable(d2)), caption = "A tale of two tables") } \references{ See diff --git a/man/knit.Rd b/man/knit.Rd index b2cc5506e9..9ddfc7ef76 100644 --- a/man/knit.Rd +++ b/man/knit.Rd @@ -149,14 +149,14 @@ The working directory when evaluating R code chunks is the directory of } \examples{ library(knitr) -(f = system.file('examples', 'knitr-minimal.Rnw', package = 'knitr')) +(f = system.file("examples", "knitr-minimal.Rnw", package = "knitr")) knit(f) # compile to tex purl(f) # tangle R code purl(f, documentation = 0) # extract R code only purl(f, documentation = 2) # also include documentation -unlink(c('knitr-minimal.tex', 'knitr-minimal.R', 'figure'), recursive = TRUE) +unlink(c("knitr-minimal.tex", "knitr-minimal.R", "figure"), recursive = TRUE) } \references{ Package homepage: \url{https://yihui.org/knitr/}. The \pkg{knitr} diff --git a/man/knit2html.Rd b/man/knit2html.Rd index 5ff0c63d52..dca88c3435 100644 --- a/man/knit2html.Rd +++ b/man/knit2html.Rd @@ -57,11 +57,12 @@ The \pkg{markdown} package is for R Markdown v1, which is much less } \examples{ # a minimal example -writeLines(c("# hello markdown", '```{r hello-random, echo=TRUE}', 'rnorm(5)', '```'), 'test.Rmd') -knit2html('test.Rmd') -if (interactive()) browseURL('test.html') +writeLines(c("# hello markdown", "```{r hello-random, echo=TRUE}", "rnorm(5)", "```"), + "test.Rmd") +knit2html("test.Rmd") +if (interactive()) browseURL("test.html") -unlink(c('test.Rmd', 'test.html', 'test.md')) +unlink(c("test.Rmd", "test.html", "test.md")) } \seealso{ \code{\link{knit}}, \code{markdown::\link{markdownToHTML}} diff --git a/man/knit_child.Rd b/man/knit_child.Rd index 5d2526f239..bf3ecc8f23 100644 --- a/man/knit_child.Rd +++ b/man/knit_child.Rd @@ -37,8 +37,8 @@ This function is not supposed be called directly like The path of the child document is determined relative to the parent document. } \examples{ -# you can write \Sexpr{knit_child('child-doc.Rnw')} in an Rnw file 'main.Rnw' -# to input results from child-doc.Rnw in main.tex +# you can write \Sexpr{knit_child('child-doc.Rnw')} in an Rnw file 'main.Rnw' to +# input results from child-doc.Rnw in main.tex # comment out the child doc by \Sexpr{knit_child('child-doc.Rnw', eval = FALSE)} } diff --git a/man/knit_engines.Rd b/man/knit_engines.Rd index 1c58edc3d5..dae268b480 100644 --- a/man/knit_engines.Rd +++ b/man/knit_engines.Rd @@ -40,7 +40,8 @@ The Leiningen engine \code{lein} requires lein-exec plugin; see \url{https://github.com/yihui/knitr/issues/1176} for details. } \examples{ -knit_engines$get('python'); knit_engines$get('awk') +knit_engines$get("python") +knit_engines$get("awk") names(knit_engines$get()) } \references{ diff --git a/man/knit_expand.Rd b/man/knit_expand.Rd index 7cf69fe0f5..501bd900a1 100644 --- a/man/knit_expand.Rd +++ b/man/knit_expand.Rd @@ -29,7 +29,7 @@ template. } \examples{ # see the knit_expand vignette -if (interactive()) browseVignettes(package='knitr') +if (interactive()) browseVignettes(package = "knitr") } \references{ This function was inspired by the pyexpander and m4 diff --git a/man/knit_filter.Rd b/man/knit_filter.Rd index cc5b0fcadd..f8213ff0b0 100644 --- a/man/knit_filter.Rd +++ b/man/knit_filter.Rd @@ -24,13 +24,14 @@ and inline expressions. } \examples{ library(knitr) -knitr_example = function(...) system.file('examples', ..., package = 'knitr') +knitr_example = function(...) system.file("examples", ..., package = "knitr") \donttest{ -if (Sys.which('aspell') != '') { -# -t means the TeX mode -utils::aspell(knitr_example('knitr-minimal.Rnw'), knit_filter, control = '-t') +if (Sys.which("aspell") != "") { + # -t means the TeX mode + utils::aspell(knitr_example("knitr-minimal.Rnw"), knit_filter, control = "-t") -# -H is the HTML mode -utils::aspell(knitr_example('knitr-minimal.Rmd'), knit_filter, control = '-H -t') -}} + # -H is the HTML mode + utils::aspell(knitr_example("knitr-minimal.Rmd"), knit_filter, control = "-H -t") +} +} } diff --git a/man/knit_hooks.Rd b/man/knit_hooks.Rd index 7f3ff1621d..fdebf7775d 100644 --- a/man/knit_hooks.Rd +++ b/man/knit_hooks.Rd @@ -16,7 +16,8 @@ arguments and returns desired output. The object \code{knit_hooks} is used to access or set hooks in this package. } \examples{ -knit_hooks$get('source'); knit_hooks$get('inline') +knit_hooks$get("source") +knit_hooks$get("inline") } \references{ Usage: \url{https://yihui.org/knitr/objects/} diff --git a/man/knit_patterns.Rd b/man/knit_patterns.Rd index a5d6a2b290..3e207f5489 100644 --- a/man/knit_patterns.Rd +++ b/man/knit_patterns.Rd @@ -19,18 +19,18 @@ and examples for usage. All built-in patterns are available in the list } \examples{ library(knitr) -opat = knit_patterns$get() # old pattern list (to restore later) +opat = knit_patterns$get() # old pattern list (to restore later) apats = all_patterns # a list of all built-in patterns str(apats) -knit_patterns$set(apats[['rnw']]) # set pattern list from apats +knit_patterns$set(apats[["rnw"]]) # set pattern list from apats -knit_patterns$get(c('chunk.begin', 'chunk.end', 'inline.code')) +knit_patterns$get(c("chunk.begin", "chunk.end", "inline.code")) # a customized pattern list; has to empty the original patterns first! knit_patterns$restore() # we may want to use this in an HTML document -knit_patterns$set(list(chunk.begin = '')) +knit_patterns$set(list(chunk.begin = "")) str(knit_patterns$get()) knit_patterns$set(opat) # put the old patterns back diff --git a/man/knit_print.Rd b/man/knit_print.Rd index d13bca3a8d..e93d8571a7 100644 --- a/man/knit_print.Rd +++ b/man/knit_print.Rd @@ -45,13 +45,13 @@ It is recommended to leave a \code{...} argument in your method, to library(knitr) # write tables for data frames knit_print.data.frame = function(x, ...) { - res = paste(c('', '', kable(x, output = FALSE)), collapse = '\n') - asis_output(res) + res = paste(c("", "", kable(x, output = FALSE)), collapse = "\n") + asis_output(res) } # register the method registerS3method("knit_print", "data.frame", knit_print.data.frame) -# after you define and register the above method, data frames will be printed -# as tables in knitr, which is different with the default print() behavior +# after you define and register the above method, data frames will be printed as +# tables in knitr, which is different with the default print() behavior } \references{ See \code{vignette('knit_print', package = 'knitr')}. diff --git a/man/knit_rd.Rd b/man/knit_rd.Rd index 097aebcc5e..062266210d 100644 --- a/man/knit_rd.Rd +++ b/man/knit_rd.Rd @@ -38,10 +38,10 @@ Ideally the html pages should be put under the \file{html} directory of library(knitr) \dontrun{ -knit_rd('maps') -knit_rd('rpart') -setwd(system.file('html', package = 'ggplot2')) -knit_rd('ggplot2') # time-consuming! +knit_rd("maps") +knit_rd("rpart") +setwd(system.file("html", package = "ggplot2")) +knit_rd("ggplot2") # time-consuming! knit_rd_all() # this may take really long time if you have many packages installed } diff --git a/man/knit_theme.Rd b/man/knit_theme.Rd index 2c5e5916b2..b58b8f76dc 100644 --- a/man/knit_theme.Rd +++ b/man/knit_theme.Rd @@ -28,14 +28,15 @@ The syntax highlighting here only applies to \file{.Rnw} (LaTeX) and highlighting themes; see \url{https://rmarkdown.rstudio.com}). } \examples{ -opts_knit$set(out.format='latex'); knit_theme$set('edit-vim') +opts_knit$set(out.format = "latex") +knit_theme$set("edit-vim") knit_theme$get() # names of all available themes -thm = knit_theme$get('acid') # parse the theme to a list +thm = knit_theme$get("acid") # parse the theme to a list knit_theme$set(thm) -opts_knit$set(out.format=NULL) # restore option +opts_knit$set(out.format = NULL) # restore option } \references{ For a preview of all themes, see diff --git a/man/opts_chunk.Rd b/man/opts_chunk.Rd index 29b16f5f25..933d069d6c 100644 --- a/man/opts_chunk.Rd +++ b/man/opts_chunk.Rd @@ -38,7 +38,8 @@ See \code{str(knitr::opts_chunk$get())} for a list of default chunk options. not recommended to do so unless you understand the consequences. } \examples{ -opts_chunk$get('prompt'); opts_chunk$get('fig.keep') +opts_chunk$get("prompt") +opts_chunk$get("fig.keep") } \references{ Usage: \url{https://yihui.org/knitr/objects/} diff --git a/man/opts_hooks.Rd b/man/opts_hooks.Rd index d2e0b59689..6673d7eabe 100644 --- a/man/opts_hooks.Rd +++ b/man/opts_hooks.Rd @@ -24,10 +24,10 @@ will be called to update the chunk options. \examples{ # make sure the figure width is no smaller than fig.height opts_hooks$set(fig.width = function(options) { - if (options$fig.width < options$fig.height) { - options$fig.width = options$fig.height - } - options + if (options$fig.width < options$fig.height) { + options$fig.width = options$fig.height + } + options }) # remove all hooks opts_hooks$restore() diff --git a/man/opts_knit.Rd b/man/opts_knit.Rd index 4c5ca19140..9d7e4415be 100644 --- a/man/opts_knit.Rd +++ b/man/opts_knit.Rd @@ -26,11 +26,12 @@ options in \file{~/.Rprofile} without loading \pkg{knitr}. See \code{str(knitr::opts_knit$get())} for a list of default package options. } \examples{ -opts_knit$get('verbose'); opts_knit$set(verbose = TRUE) # change it +opts_knit$get("verbose") +opts_knit$set(verbose = TRUE) # change it if (interactive()) { -# for unnamed chunks, use 'fig' as the figure prefix -opts_knit$set(unnamed.chunk.label='fig') -knit('001-minimal.Rmd') # from https://github.com/yihui/knitr-examples + # for unnamed chunks, use 'fig' as the figure prefix + opts_knit$set(unnamed.chunk.label = "fig") + knit("001-minimal.Rmd") # from https://github.com/yihui/knitr-examples } } \references{ diff --git a/man/output_type.Rd b/man/output_type.Rd index 6aeedc4f41..62270b4333 100644 --- a/man/output_type.Rd +++ b/man/output_type.Rd @@ -37,5 +37,5 @@ default, these formats are considered as HTML formats: \code{c('markdown', \examples{ knitr::is_latex_output() knitr::is_html_output() -knitr::is_html_output(excludes = c('markdown', 'epub')) +knitr::is_html_output(excludes = c("markdown", "epub")) } diff --git a/man/pandoc.Rd b/man/pandoc.Rd index 75f6d0eb75..79d7f32fee 100644 --- a/man/pandoc.Rd +++ b/man/pandoc.Rd @@ -51,7 +51,7 @@ input markdown file will be converted to all these formats by default, unless the \code{format} argument is specified as one single format. } \examples{ -system('pandoc -h') # see possible output formats +system("pandoc -h") # see possible output formats } \references{ Pandoc: \url{https://pandoc.org}; Examples and rules of the diff --git a/man/pat_fun.Rd b/man/pat_fun.Rd index 839b17fe4c..e6ccfb5ec2 100644 --- a/man/pat_fun.Rd +++ b/man/pat_fun.Rd @@ -39,7 +39,9 @@ documents. } \examples{ # see how knit_patterns is modified -knit_patterns$get(); pat_rnw(); knit_patterns$get() +knit_patterns$get() +pat_rnw() +knit_patterns$get() knit_patterns$restore() # empty the list } diff --git a/man/rand_seed.Rd b/man/rand_seed.Rd index cf39cf0205..4c540a4416 100644 --- a/man/rand_seed.Rd +++ b/man/rand_seed.Rd @@ -18,7 +18,7 @@ references. } \examples{ eval(rand_seed) -rnorm(1) # .Random.seed is created (or modified) +rnorm(1) # .Random.seed is created (or modified) eval(rand_seed) } \references{ diff --git a/man/raw_block.Rd b/man/raw_block.Rd index fa128f402e..6ece27320b 100644 --- a/man/raw_block.Rd +++ b/man/raw_block.Rd @@ -29,5 +29,5 @@ Functions \code{raw_latex()} and \code{raw_html()} are shorthands of \code{raw_block(x, 'latex')} and \code{raw_block(x, 'html')}, respectively. } \examples{ -knitr::raw_latex('\\\\emph{some text}') +knitr::raw_latex("\\\\emph{some text}") } diff --git a/man/raw_output.Rd b/man/raw_output.Rd index 7269e29e9d..eeb7b6279b 100644 --- a/man/raw_output.Rd +++ b/man/raw_output.Rd @@ -52,11 +52,14 @@ output. } \examples{ library(knitr) -out = c('*hello*', raw_output('content *protect* me!'), '*world*') +out = c("*hello*", raw_output("content *protect* me!"), + "*world*") pre = extract_raw_output(out) str(pre) -pre$value = gsub('[*]([^*]+)[*]', '\\\\1', pre$value) # think this as Pandoc conversion +pre$value = gsub("[*]([^*]+)[*]", "\\\\1", + pre$value) # think this as Pandoc conversion pre$value -# raw output was protected from the conversion (e.g. *protect* was not converted) +# raw output was protected from the conversion (e.g. +# *protect* was not converted) restore_raw_output(pre$value, pre$chunks) } diff --git a/man/read_chunk.Rd b/man/read_chunk.Rd index 2cb6654223..c9116542a6 100644 --- a/man/read_chunk.Rd +++ b/man/read_chunk.Rd @@ -80,24 +80,25 @@ This function can only be used in a chunk which is \emph{not} cached ## put this in foo.R and read_chunk('foo.R') ## ---- my-label ---- -1+1 -lm(y~x, data=data.frame(x=1:10,y=rnorm(10))) +1 + 1 +lm(y ~ x, data = data.frame(x = 1:10, y = rnorm(10))) ## later you can use <>= to reference this chunk ## the 2nd approach -code = c("#@a", '1+1', "#@b", "#@a", 'rnorm(10)', "#@b") -read_chunk(lines = code, labels = 'foo') # put all code into one chunk named foo -read_chunk(lines = code, labels = 'foo', from = 2, to = 2) # line 2 into chunk foo -read_chunk(lines = code, labels = c('foo', 'bar'), from = c(1, 4), to = c(3, 6)) +code = c("#@a", "1+1", "#@b", "#@a", "rnorm(10)", "#@b") +read_chunk(lines = code, labels = "foo") # put all code into one chunk named foo +read_chunk(lines = code, labels = "foo", from = 2, to = 2) # line 2 into chunk foo +read_chunk(lines = code, labels = c("foo", "bar"), from = c(1, 4), to = c(3, 6)) # automatically figure out 'to' -read_chunk(lines = code, labels = c('foo', 'bar'), from = c(1, 4)) -read_chunk(lines = code, labels = c('foo', 'bar'), from = "^#@a", to = "^#@b") -read_chunk(lines = code, labels = c('foo', 'bar'), from = "^#@a", to = "^#@b", from.offset = 1, to.offset = -1) +read_chunk(lines = code, labels = c("foo", "bar"), from = c(1, 4)) +read_chunk(lines = code, labels = c("foo", "bar"), from = "^#@a", to = "^#@b") +read_chunk(lines = code, labels = c("foo", "bar"), from = "^#@a", to = "^#@b", + from.offset = 1, to.offset = -1) ## later you can use, e.g., <>= -knitr:::knit_code$get() # use this to check chunks in the current session -knitr:::knit_code$restore() # clean up the session +knitr:::knit_code$get() # use this to check chunks in the current session +knitr:::knit_code$restore() # clean up the session } \references{ \url{https://yihui.org/knitr/demo/externalization/} diff --git a/man/read_rforge.Rd b/man/read_rforge.Rd index 758c1e66cb..3450415e15 100644 --- a/man/read_rforge.Rd +++ b/man/read_rforge.Rd @@ -22,9 +22,11 @@ This function reads source code from the SVN repositories on R-Forge. } \examples{ library(knitr) -\donttest{# relies on r-forge.r-project.org being accessible -read_rforge('rgl/R/axes.R', project = 'rgl') -read_rforge('rgl/R/axes.R', project = 'rgl', extra='&revision=519')} +\donttest{ +# relies on r-forge.r-project.org being accessible +read_rforge("rgl/R/axes.R", project = "rgl") +read_rforge("rgl/R/axes.R", project = "rgl", extra = "&revision=519") +} } \author{ Yihui Xie and Peter Ruckdeschel diff --git a/man/rocco.Rd b/man/rocco.Rd index 4c15c18412..aa9b6dcf13 100644 --- a/man/rocco.Rd +++ b/man/rocco.Rd @@ -26,14 +26,18 @@ the key \code{t} to hide the code column (show the text column only), and press again to hide the text column (show code). } \examples{ -rocco_view=function(input) { -owd = setwd(tempdir()); on.exit(setwd(owd)) -if (!file.exists(input)) return() -o=rocco(input, header='', quiet=TRUE) -if (interactive()) browseURL(o)} +rocco_view = function(input) { + owd = setwd(tempdir()) + on.exit(setwd(owd)) + if (!file.exists(input)) + return() + o = rocco(input, header = "", quiet = TRUE) + if (interactive()) + browseURL(o) +} # knit these two vignettes using the docco style -rocco_view(system.file('doc', 'docco-classic.Rmd', package = 'knitr')) -rocco_view(system.file('doc', 'knit_expand.Rmd', package = 'knitr')) +rocco_view(system.file("doc", "docco-classic.Rmd", package = "knitr")) +rocco_view(system.file("doc", "knit_expand.Rmd", package = "knitr")) } \references{ The Docco package by Jeremy Ashkenas: diff --git a/man/set_alias.Rd b/man/set_alias.Rd index b8afa52a4b..ef58a359dc 100644 --- a/man/set_alias.Rd +++ b/man/set_alias.Rd @@ -19,6 +19,7 @@ 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. } \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 +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 } diff --git a/man/set_header.Rd b/man/set_header.Rd index b24f7ea820..da39246454 100644 --- a/man/set_header.Rd +++ b/man/set_header.Rd @@ -39,6 +39,6 @@ definitions of the \pkg{listings} package (and modify the output hooks accordingly), so we can decorate R code using the \pkg{listings} package. } \examples{ -set_header(tikz = '\\\\usepackage{tikz}') -opts_knit$get('header') +set_header(tikz = "\\\\usepackage{tikz}") +opts_knit$get("header") } diff --git a/man/stitch.Rd b/man/stitch.Rd index 53f557a177..8ccb207fe5 100644 --- a/man/stitch.Rd +++ b/man/stitch.Rd @@ -57,16 +57,16 @@ headers are found, the whole R script will be inserted into the template as one code chunk. } \examples{ -s = system.file('misc', 'stitch-test.R', package = 'knitr') +s = system.file("misc", "stitch-test.R", package = "knitr") if (interactive()) stitch(s) # compile to PDF # HTML report -stitch(s, system.file('misc', 'knitr-template.Rhtml', package = 'knitr')) +stitch(s, system.file("misc", "knitr-template.Rhtml", package = "knitr")) # or convert markdown to HTML -stitch(s, system.file('misc', 'knitr-template.Rmd', package = 'knitr')) +stitch(s, system.file("misc", "knitr-template.Rmd", package = "knitr")) -unlink(c('stitch-test.html', 'stitch-test.md', 'figure'), recursive = TRUE) +unlink(c("stitch-test.html", "stitch-test.md", "figure"), recursive = TRUE) } \seealso{ \code{\link{spin}} (turn a specially formatted R script to a report) diff --git a/man/vignette_engines.Rd b/man/vignette_engines.Rd index ad40965402..5883ba761b 100644 --- a/man/vignette_engines.Rd +++ b/man/vignette_engines.Rd @@ -30,9 +30,9 @@ If you use the \code{knitr::rmarkdown} engine, please make sure that } \examples{ library(knitr) -vig_list = tools::vignetteEngine(package = 'knitr') +vig_list = tools::vignetteEngine(package = "knitr") str(vig_list) -vig_list[['knitr::knitr']][c('weave', 'tangle')] -vig_list[['knitr::knitr_notangle']][c('weave', 'tangle')] -vig_list[['knitr::docco_classic']][c('weave', 'tangle')] +vig_list[["knitr::knitr"]][c("weave", "tangle")] +vig_list[["knitr::knitr_notangle"]][c("weave", "tangle")] +vig_list[["knitr::docco_classic"]][c("weave", "tangle")] } diff --git a/man/wrap_rmd.Rd b/man/wrap_rmd.Rd index 6f377cdece..2418476253 100644 --- a/man/wrap_rmd.Rd +++ b/man/wrap_rmd.Rd @@ -33,6 +33,6 @@ Currently it does not wrap blockquotes or lists (ordered or unordered). This feature may or may not be added in the future. } \examples{ -wrap_rmd(text = c('```', '1+1', '```', '- a list item', '> a quote', '', -paste(rep('this is a normal paragraph', 5), collapse = ' '))) +wrap_rmd(text = c("```", "1+1", "```", "- a list item", "> a quote", "", + paste(rep("this is a normal paragraph", 5), collapse = " "))) } diff --git a/man/write_bib.Rd b/man/write_bib.Rd index e093991fe6..a32811f2f8 100644 --- a/man/write_bib.Rd +++ b/man/write_bib.Rd @@ -70,14 +70,14 @@ Some packages on CRAN do not have standard bib entries, which was once \file{inst/misc/tweak_bib.csv} in the source package. } \examples{ -write_bib(c('RGtk2', 'gWidgets'), file = 'R-GUI-pkgs.bib') -unlink('R-GUI-pkgs.bib') +write_bib(c("RGtk2", "gWidgets"), file = "R-GUI-pkgs.bib") +unlink("R-GUI-pkgs.bib") -write_bib(c('animation', 'rgl', 'knitr', 'ggplot2')) -write_bib(c('base', 'parallel', 'MASS')) # base and parallel are identical -write_bib('cluster', prefix = '') # a empty prefix -write_bib('digest', prefix = 'R-pkg-') # a new prefix -write_bib('digest', tweak = FALSE) # original version +write_bib(c("animation", "rgl", "knitr", "ggplot2")) +write_bib(c("base", "parallel", "MASS")) # base and parallel are identical +write_bib("cluster", prefix = "") # a empty prefix +write_bib("digest", prefix = "R-pkg-") # a new prefix +write_bib("digest", tweak = FALSE) # original version # what tweak=TRUE does str(knitr:::.tweak.bib) From cfe6e579f97cfdd27a5f9400617fc58c04243c81 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 11 Mar 2021 14:04:15 -0600 Subject: [PATCH 14/15] add a news item --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 62e003b92e..54ad461f2e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## NEW FEATURES +- The internal code to process R code chunks was factored out into the language engine `R`, which can be obtained via `knit_engines$get('R')` now (thanks, @abhsarma, #1963). + - Added arguments `dir` and `envir` to `load_cache()` to specify the working directory and environment into which the cached objects are loaded. By default, all cached objects are loaded into the global environment, which may not be desirable (thanks, @LTLA, #1905). - The internal function `html_screenshot()`, which takes screenshots of HTML widgets and Shiny apps in **knitr** documents, now prefers the **webshot2** package over the **webshot** package. This is because the backend of the **webshot** package is PhantomJS, which [has been archived since 2018](https://github.com/ariya/phantomjs/issues/15344). If **webshot** is still preferred, use the chunk option `opts_chunk$set(webshot = "webshot")` (thanks, @atusy #1918, @LouisStAmour #1858). From c9753a22f6c7ed25bb926583e2b07c8730c6fe70 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 11 Mar 2021 14:06:16 -0600 Subject: [PATCH 15/15] add @abhsarma to the list of contributors --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 67143b8425..d92cfe478b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,6 +4,7 @@ Title: A General-Purpose Package for Dynamic Report Generation in R Version: 1.31.5 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), + person("Abhraneel", "Sarma", role = "ctb"), person("Adam", "Vogt", role = "ctb"), person("Alastair", "Andrew", role = "ctb"), person("Alex", "Zvoleff", role = "ctb"),