A general-purpose tool for dynamic report generation in R
Office outputs (e.g., rmarkdown::word_document
) supports the following chunk options out.width
, out.height
, out.extra
. Their behavior follows the behavior of Pandoc's link_attributes
extention (thanks, @atusy, #1746).
The chunk option fig.process
can be specified by a function with the options
argument to read chunk options (thanks, @atusy, #1749).
For kable(format = 'latex')
, a single string consisting of l
, c
, and r
for the align
argument also works now, e.g., knitr::kable(head(iris), 'latex', align = 'llcrr')
. Previously it has to be a character vector of individual letters.
valign
argument of kable(format = 'latex')
meant to control the vertical alignment of the inner tabular
environment, instead of the floating position of the outer table
environment. A separate argument named position
has been added to control the floating position (e.g., position = "!b"
).combine_words()
is wrapped in xfun::raw_string()
for pretty printing.The output
hook for render_sweave()
failed to respect the chunk option results='asis'
(thanks, Achim Zeileis, https://stackoverflow.com/q/57571790/559676).
Added the unit px
to the chunk option out.width
if its value is numeric (thanks, @chendaniely, #1761).
The chunk option dependson
did not work for non-R engines (thanks, @nielsrhansen, #1601).
The input
argument of knitr::knit()
must be a file path (a character string). It can no longer be connections.
The encoding
argument of knitr::knit()
is ignored. The encoding is always assumed to be UTF-8. Please see https://yihui.name/en/2018/11/biggest-regret-knitr/ for more info.
\n
now. This will avoid errors when a python code chunk contains a reference to a code chunk that contains multiple statements (thanks, @Atrebas, rstudio/rmarkdown#1589).Added mogrify
support in hook_png()
and hook_mogrify()
in order to obtain trimmed .png
files (thanks, @mhofert, #1697).
It is possible to customize the sign \times
used for the scientific notation of inline numeric output via a global option, e.g., options(knitr.inline.times = '\\cdot ')
(thanks, @wuffi @trentks, #1563).
Exported knit_code
and documented it at ?knitr::knit_code
. Here be dragons, but I know you are brave and creative (thanks, @r-cheologist @ProQuestionAsker, #1545).
Added support for specifying fenced code block attributes in Markdown output via chunk options attr.*
, which are similar but a generalization to the existing chunk options class.*
. For example, class.source = 'numberLines'
is equivalent to attr.source = '.numberLines'
, but attr.source
can take arbitrary attribute values, e.g., attr.source = c('.numberLines', 'startFrom="11"')
(thanks, @atusy, #1710).
For R Markdown documents, inline numeric output that is formatted with the scientific notation will be wrapped in \ensuremath{}
. This will fix the LaTeX error ! Missing $ inserted.
. However, you are still recommended to add a pair of dollar signs around the inline output when it is formatted with the scientific notation (e.g., $`r 1.234e12`$
), otherwise it will not work with other R Markdown output formats such as HTML or Word (thanks, @billdenney and many who have suffered from this issue, rstudio/rmarkdown#1527).
For an input file that contains no code chunks or inline R code expressions, purl()
should return an empty string instead of the original text from the input (thanks, @jrnold, #1660).
purl()
might trigger a warning for non-R code chunks (thanks, @adamcagle, rstudio/rmarkdown#1528).
When building package vignettes via R CMD build
, the R scripts generated from knitr's vignette (tangling) engines are not corrected encoded in UTF-8 (thanks, Kurt Hornik).
Fixed a bug introduced when fixing #1648: include_url()
no longer works at all unless the chunk option out.extra
is not empty (thanks, @gabrielvazdemelo, #1691).
When evaluating perl code chunks the interpreter is spawned with the -E
option, enabling all optional features such as say
, rather than -e
(thanks, @kiwiroy, #1699)
When the chunk label of a tikz
chunk contains periods, the tikz
output cannot be converted to the expected .svg
(thanks, @ucpresearch, #1706).
The ...
argument for raw_latex()
and raw_html()
is actually passed to asis_output()
now (thanks, @GregorDeCillia, #1716).
knitr::knit()
will try to read the input file with the UTF-8 encoding first. If UTF-8 doesn't work, it will try to read with the system native encoding instead (with a warning). The encoding
argument of knitr::knit()
is completely ignored. In the future, only UTF-8 will be supported, and we will stop retrying with the system native encoding. The output file from knitr::knit()
is always encoded in UTF-8.
spin_child()
will also assume the input file is encoded in UTF-8 (thanks, Henrik, https://stackoverflow.com/q/55395422/559676).
When the chunk option dev = 'svg'
, grDevices::svg()
is used to record plots, instead of the default PDF null device (thanks, @trevorld, #729).
Partially reverted the solution for #1403 in favor of fixing the more surprising issue #1708, i.e., avoid false positive cache dependencies among chunks more than false negative dependencies when the chunk option autodep = TRUE
(thanks, @fountainer).
The LaTeX package framed.sty
is no longer bundled with the knitr package. This should only affect users who write .Rnw
documents. If framed.sty
is missing in your LaTeX distribution, you will have to install it by yourself. You may also consider TinyTeX (https://yihui.name/tinytex/), which has included this LaTeX package.
Added chunk options class.error
, class.warning
, and class.message
to customize the CSS classes for errors, warnings, and messages in R Markdown output, respectively (thanks, @gadenbuie, #1676).
Added a new engine sass
/scss
to convert Sass/SCSS to CSS using either the sass R package (LibSass) or Dart Sass executable (when R package not found, the engine option engine.opts = list(package = FALSE)
, or engine.path
to executable is provided). After conversion, resulting CSS is treated as in the CSS engine (thanks, @emilyriederer, #1666).
The cat
engine supports the chunk option eval = FALSE
now (thanks, @HanOostdijk, #1618).
The chunk option out.extra
can be used to include extra attributes for the <iframe>
generated from knitr::include_url()
or knitr::include_app()
(thanks, @jvcasillas, #1648).
knit_meta_add()
could exhaust the system's memory because of a wrong method of vectorization (thanks, @kevinushey @nikkoc, rstudio/rmarkdown#1538).
The output path should be quoted in pandoc()
(thanks, @antoine-sachet, #1644).
When there are multiple figures with multiple captions in a code chunk, bookdown's figure numbering is incorrect (thanks, Catherine Peng, https://stackoverflow.com/q/53880195/559676).
Added an argument label
to kable()
so that users can manually specify a label (thanks, @Inferrator, #1655).
The chunk option fig.show='hide'
doesn't work for knitr::include_graphics()
(thanks, @vincentarelbundock, #1675).
The tikz
engine doesn't work on Windows (thanks, Andry, https://stackoverflow.com/q/54839403/559676).
kable()
now generates a table for R Markdown documents even when the data has 0 rows (thanks, @yutannihilation, #1677).
The chunk options dev = 'tikz'
and external = FALSE
didn't work in R Markdown (thanks, @martinschmelzer, #1649).
knitr::knit()
starts to warn against non-UTF8 encodings (Why?). In the future, we will only support UTF-8 input. If your input file is not encoded in UTF-8, we strongly recommend that you re-save it with UTF-8.
Removed the encoding
arguments in knitr::pandoc()
, knitr::knit2pdf()
, knitr2wp()
, and knitr::Sweave2knitr()
. The input files must be encoded in UTF-8.
knitr::knit2html()
still has the encoding
argument, but it only supports UTF-8 internally.
Changed tools::texi2dvi()
to tinytex::latexmk()
for the tikz
engine to compile TikZ graphics to other foramts (e.g., svg
or png
). This requires the tinytex package >= v0.10.10: https://github.com/yihui/tinytex.
Empty lines are no longer removed in the output of purl()
(thanks, Marius Hofert).
Added styler support: the chunk option tidy = 'styler'
, the code will be reformatted using the styler package. The chunk option tidy = TRUE
means tidy = 'formatR'
and still uses formatR::tidy_source()
to reformat the code. The chunk option tidy
can also take a custom function to reformat the code. See the documentation for details: https://yihui.name/knitr/options/ (thanks, @lorenzwalthert, #1581).
Added a new hook function hook_gifski()
to create a GIF animation from plots in a code chunk. To enable this hook, you may install.packages('gifski')
and set the chunk option animation.hook='gifski'
. See https://yihui.name/en/2018/08/gifski-knitr/ for examples.
Added a new object cache_engines
for other language engines to handle caching. See ?knitr::cache_engines
for details (thanks, @tmastny, #1518).
Can now pass additional arguments to knitr vignette engines if needed (thanks, @jimhester, #1577).
When options(knitr.include_graphics.ext = TRUE)
is set, the full filename will be used in \includegraphics{}
(e.g., \includegraphics{foo.pdf}
) instead of the (default) base filename (e.g., \includegraphics{foo}
) if a plot is embedded in the LaTeX output. This will avoid the ambiguity for LaTeX to choose the correct file (#1587).
The chunk option engine.opts
can also take a list now, so that users can specify different options for different language engines (thanks, @kiwiroy, #1632).
Added functions raw_block()
, raw_latex()
, and raw_html()
to wrap content in raw attribute blocks for Pandoc (thanks, @hughjonesd, #1633).
valign
in kable_latex()
does not put the float alignment to the correct location (thanks, @haozhu233, #1487, #1519).
engine.path
does not work for engine = 'dot'
(thanks, @billy34, #1534).
The sql
engine now caches the result properly when the chunk option output.var
is specified (thanks, @yutannihilation, #1544).
knit_params()
mangles UTF-8 text not representable in current locale (thanks, @kevinushey, #1557).
The linesep
argument in kable(format = 'latex')
does not work as expected (thanks, @tinu-schneider, #1558).
MP4 generated by hook_ffmpeg()
does not work in Safari (thanks, @brianzhang01, #1586).
The chunk option fig.env
does not work for PDF output from R Markdown (thanks, @RSchwinn, #1620).
spin()
fails to generate a proper R Markdown document when the R script contains roxygen comments as string literals or more than three backticks (thanks, @yutannihilation, #1605, #1611).
Stan chunks cannot be properly cached: the bug #1064 appeared again (thanks, Mark, https://stackoverflow.com/q/53660143/559676).
Roman numerals should not be converted to arabic numerals in inline R expressions (thanks, @rgaiacs, #1625).
For R scripts passed to spin()
, only the UTF-8 encoding is accepted (previously it assumes the native encoding of the system).
Due to changes in the S3 method dispatch mechanism since R 3.5.0, you will have to call registerS3method()
to register knit_print
methods defined in code chunks. For package authors, it no longer suffices to export a method without importing knitr::knit_print
, but if you don't want to import it, there is still a workaround. See the package vignette vignette('knit_print', package = 'knitr')
for details (thanks, @wch @kevinushey @skranz #1580).
spin()
will close each individual code chunk if multiple code chunks appear consecutively (previously it only closes the last code chunk in this case) (thanks, @avehtari, #1590).roxygen_comments
parameter to read_chunk()
in order to control whether trailing commentary is stripped from code chunks; default behaviour is to keep roxygen comments with roxygen_comments = TRUE
(thanks, @ruaridhw, #1484).knit_filter()
does not work for R Markdown input files (thanks, @omahdi, #1498).spin()
now supports code chunks of the form -- ---- label ----
allowing external SQL and Haskell files to be spun (thanks, @ruaridhw, #1492)tinytex::latexmk()
is used to compile LaTeX plots generated by the chunk option dev = 'tikz'
to PDF, which means you have to install the tinytex package if you use this device.
Similarly, tinytex::latexmk()
is used in knit2pdf()
and stitch()
.
Fixed rstudio/bookdown#501: the chunk option out.height
can also take a percentage value when the output format is LaTeX (similar to out.width
), e.g., out.height = '30%'
means .3\textheight
(thanks, @dataopt, #1482).
imgur_upload()
starts to fail due to changes in Imgur's API (thanks, @jennybc, #1495).
added a new engine julia
based on JuliaCall::eng_juliacall()
to support Julia code chunks (thanks, @Non-Contradiction, #1458)
added a new chunk option fig.dim
to specify fig.width
and fig.height
using one option, e.g., fig.dim = c(5, 7)
is a shorthand of fig.width = 5, fig.height = 7
(thanks, @MichaelChirico, #1449)
added two chunk options fig.ncol
and fig.sep
to make it possible to arrange multiple subfigures in columns (thanks, @eliocamp, #1444)
exported function is_latex_output()
and is_html_output()
(thanks, @zeehio, rstudio/rmarkdown#649)
for read_chunk()
, the code chunks in the external R script can be written under lines of the form -- ---- label ----
now (# ---- label ----
is still supported); this makes it possible to read an external Haskell script (thanks, @brittAnderson, #1455)
added a $append()
method to the internal function new_defaults()
(thanks, @yonicd, #1417)
added another usage of engine_output()
for expert users: if you are familiar with the list structure of the evaluate::evaluate()
output, you can let your custom engine return a similar list and call engine_output(options, out = YOUR_LIST)
(thanks, @kevinushey, #1442)
added an evaluate.inline
hook to knit_hooks
(thanks, @kevinushey, #1443)
the python
engine is based on reticulate::eng_python()
now; this means all Python code chunks are evaluated in the same Python session; if you want the old behavior (new session for each Python code chunk), you can set the chunk option python.reticulate = FALSE
(thanks, @kevinushey, #1440)
the auto_pdf
argument of include_graphics()
defaults to FALSE
now; you can set options(knitr.graphics.auto_pdf = TRUE)
to change the default to TRUE
(thanks, @mebden, #1456)
fixed #1446: knitr may fail to parse code chunks in blockquotes in Markdown (thanks, @rgaiacs)
fixed #1460: kable()
does not generate the table caption when the data only has one column (thanks, @Henrik-P)
fixed #1464: subcaptions are not rendered if the chunk option out.extra = NULL
and the output format is LaTeX (thanks, @eliocamp)
fixed #1462: kable()
may mis-order column names of data generated by sparklyr (thanks, @JohnMount)
the automatic detection of chunk dependencies (via the chunk option autodep = TRUE
) is more conservative by default now; chunk B depends on chunk A if any variables in B are created in A, no matter if these variables are local or global in B; you can use the chunk option cache.globals
to manually provide a vector of variable names that should be considered "global" to avoid the dependency when local variables in B are also found in A (thanks, @knokknok, #1403)
for engines css
and js
, the source code will be displayed by default just like R code chunks, and you can hide the source code using the chunk option echo = FALSE
(thanks, @skadauke, #1408)
for kable()
, the digits
argument will be applied to columns of the class difftime
(thanks, @RoyalTS, #1396)
when a table only has one column, kable()
does not work in R Markdown documents (thanks, @expersso, https://github.com/yihui/printr/issues/31)
message(..., appendLF = FALSE)
does not work (thanks, Anastasius, http://stackoverflow.com/q/44059508/559676)
hook_optipng()
does not work correctly when a code chunk does not contain any R-generated plots (thanks, @@zevross-spatial, #1404)
markdown lines starting with three backticks won't be considered inline code chunks (thanks, @gadenbuie, #1416)