Releases: yihui/knitr
knitr 1.31
NEW FEATURES
-
Exported the functions
pandoc_to()andpandoc_from()to get the output and input Pandoc format respectively when knitting R Markdown documents (thanks, @cderv, #1951). -
Added a new chunk option
fig.altfor users to specify the alternative text in thealtattribute of the<img>tag (images). Previously, thealtattribute takes value from the chunk optionfig.cap(it still does so iffig.altisNULL). If there are multiple plots/images in a chunk, you can pass a character vector tofig.alt, and it will be applied to individual images (thanks, @cderv, #1900). -
include_url()andinclude_app()can now take a vector of URLs (thanks, @cderv, #1948). -
The
sqlengine now correctly captures error with the chunk optionerror = TRUE(thanks, @colearendt, rstudio/rmarkdown#1208). -
The chunk option
collapse = TRUEnow works as expected when the chunk optionattr.*orclass.*is provided. By this change, The chunk optioncollapse = TRUEforcesattr.*andclass.*beNULLexcept for the chunk optionsattr.sourceandclass.source(thanks, @aosavi @cderv @atusy, #1902 #1906). -
New links added in
?knitr::kable()help page to the Rmarkdown Cookbook relevant pages. -
The table label can be disabled via
kable(label = NA)now (thanks, @NickCH-K, #1937). -
The
table.attrargument inkable(.., format = 'html')can take the value from the global optionknitr.table.html.attrnow (thanks, @cderv, #1922). -
Added a new argument
oxford_commato the functioncombine_words()(thanks, @thompsonsed, #1946). -
The label prefix of tables generated by
kable()can be customized via the package optionlabel.prefixinopts_knitnow. This option takes a named character vector, and the default isknitr::opts_knit$set(label.prefix = c(table = 'tab:')). If you want to use a different prefix such astbl, you may set the option toc(table = 'tbl:')(thanks, @luispfonseca, #1890). -
The global option
options(knitr.device.fallback = TRUE)can be used to allow the graphical device specified in the chunk optiondevto fall back to other usable devices if the specified device is not operational. Users can provide a list of fallback devices via the global option, e.g.,options(knitr.device.choices = list(png = c('jpeg', 'svg'), jpeg = c('tiff'))), which means thepngdevice can fall back tojpegandsvg(the first operational device in the list is used) andjpegcan fall back totiff.
BUG FIXES
- Line numbers in error messages are incorrect when the error occurs in a child Rmd document (thanks, @cderv @khughitt, #1945).
MAJOR CHANGES
- Previously
knit_exit()in a child document would not terminate the knitting process of its parent document. Now it will terminate the whole process by default. You can useknit_exit(fully = FALSE)to exit the child document only (thanks, @davidchall, #1810).
MINOR CHANGES
- Vignette engines for R Markdown vignettes no longer check for availability of
pandoc-citeprocsince it has gone since Pandoc 2.11.
knitr 1.30
NEW FEATURES
-
Added
knitr::hooks_*()functions to get a list of output hooks for a specific format. Previously, these hooks only exist inside theknitr::render_*()functions, and users do not have direct access to them. Now they can be accessed directly, e.g., viaknitr::hooks_markdown()to get a list of output hooks for R Markdown documents. You can also set the output hooks individually, e.g.,knitr::knit_hooks$set(knitr::hooks_markdown()['source'])only sets the source ouput hook. See more on output hooks at https://yihui.org/knitr/hooks/#output-hooks and https://bookdown.org/yihui/rmarkdown-cookbook/output-hooks.html (thanks, @cderv, #1889). -
Added an argument
lib.loctoknitr::write_bib().
BUG FIXES
-
The option
fig_caption = FALSEforrmarkdown::html_document()was unable to suppress the figure captions in some cases. -
The internal function
fix_options()should be called after option hooks are executed (thanks, @atusy, #1876 and #1877). -
When the option
options(OutDec = )is set to a value other than".", percentages in the chunk optionsout.widthandout.heightdo not work (thanks, @omgitsmoe, #1887).
MINOR CHANGES
-
knitr::write_bib()removes pairs of single quotes in the titles of citation entries now. -
knitr::write_bib()uses theURLin the packageDESCRIPTIONif it is provided, instead of the canonical CRAN URL for the package. -
hook_pdfcrop()andplot_crop()will work only when both programspdfcropandghostscripthave been installed. Previously onlypdfcropwas checked (thanks, @dalupus, #954).
knitr 1.29
NEW FEATURES
-
Added a new function
kables()(the plural form ofkable()) to create a table containing multiple tables, with each table created bykable(). Previously you can only create such a table fromkable(list(data1, data2)), and now you can also dokables(list(kable(data1), kable(data2))). The latter way gives you more freedom to control each table individually via the arguments of each individualkable()call. -
The graphics device chunk option,
dev, now supports a value of'ragg_png'which calls theagg_png()function from the ragg package (thanks, @cpsievert, #1834). -
The argument
errorofinclude_graphics()takes value from the global R optionknitr.graphics.errorby default, e.g., you may setoptions(knitr.graphics.error = FALSE)soinclude_graphics()won't signal an error if the graphics file to be included doesn't exist. -
Added a new engine
ccto compile C++ code viaR CMD SHILIBlike thecandfortranengines (thanks, @kingaa, #1832).
BUG FIXES
-
For non-R code chunks that generate plots and use the chunk option
fig.cap, theplothook in knitr stopped working in v1.27 and v1.28 (thanks, @XiangyunHuang, https://d.cosx.org/d/421249). -
The
sqlengine fails when the first column of the database is of the typebit64::integer64(thanks, @randy3k, #1837). -
The chunk option
dpiis correctly passed toshowtext::showtext_opts()now (thanks, @cpsievert, yixuan/showtext#33). -
Theorem environments in bookdown fail to work with Pandoc >= 2.7.3 because of an issue in the
block2engine of knitr (rstudio/bookdown#883).
MAJOR CHANGES
-
For R Markdown documents, the default table format generated by
kable()was changed from Pandoc's simple tables to pipe tables. This fixes bugs #1788 (kable()fails to align columns containing wide characters) and #1817 (broken column headers) (thanks, @atusy, #1830). -
When a code chunk generates multiple plots to be placed in figure environments, their figure labels will be of the form
label-iwherelabelis the chunk label, andiis the plot number. Previously, the labels were of the formlabeli(i.e., there was not a dash before the number). If you cross-reference the figures, you need to change the reference keys fromlabelitolabel-i. -
For a non-matrix object passed to
kable(), its columns are formatted individually viaformat(). Previously, the whole object is coerced viaas.matrix()(thanks, @thebioengineer, #1827). -
For packages that contain R Markdown vignettes using the vignette engines based on the markdown package (e.g.,
knitr::knitr), the markdown package should be declared inSuggestsin the packageDESCRIPTIONunless it has already been declared as a dependency in other fields. For this version of knitr, you will see a warning inR CMD checkin the CRAN incoming check. In the future, you may see a warning in a regularR CMD check, so please add markdown toSuggestsat your earliest convenience. If it is not clear how to do it, please see #1864.
MINOR CHANGES
-
knitr::image_uri()callsxfun::base64_uri()instead ofmarkdown:::.b64EncodeFile()now. -
knitr::write_bib()now adds an empty line after each BibTeX entry (#1862).
knitr 1.28
BUG FIXES
hook_pdfcrop()no longer crops images included viainclude_graphics()now (thanks, @hpages #1797, @salim-b #1800).
MAJOR CHANGES
-
If the
hook_pdfcrop()is enabled, the non-PDF image will be cropped only if the magick package is available, otherwise it will signal a message. In the previous version, it will signal an error (thanks, @trannhatanh89, #1796). -
By default,
include_graphics(files)will signal an error if anyfilesdo not exist and are not web resources. To avoid the error (e.g., if you think it is a false positive), useinclude_graphics(..., error = FALSE)(thanks, @hadley, #1717).
knitr 1.27
NEW FEATURES
- The chunk option
message = FALSEcan now be used to suppress the message "running: command ..." when the language engine is a command such asbash,awk,perl,ruby,sas,sed, andstata, etc. (thanks, @splaisan, #1782).
BUG FIXES
-
The figure caption was placed incorrectly when there are multiple
include_graphics()in a code chunk (thanks, @hadley #1771, @cderv #1776). -
The chunk option
fig.keepwas buggy when taking a numeric vector. The bug was originally introduced in #1265 and discovered in the SO post https://stackoverflow.com/q/59180351/559676. -
When the chunk option
dev = 'tikz'and a plot in the code chunk is generated by ggplot2 with a legend on a continuous scale, tikzDevice will create a raster image for the legend. Now the path to the raster image in the.texfile is tweaked to include the dir name of the.texfile, so that the.texfile can be correctly compiled to PDF via LaTeX (thanks to @rstub for the debugging at https://stackoverflow.com/a/58410965/559676). -
hook_pdfcrop()does not crop all plots when multiple graphical devices are used in a code chunk (i.e., the chunk optiondevtakes a vector of devices) due to a bug in the internal functionall_figs()identified by @bastistician in #1766, who also proposed a fix.
MAJOR CHANGES
options('width')no longer affects caching. With this change, your previous cache will be invalidated if you update knitr from 1.26 to 1.27. If you prefer that changes in the R global optionwidthinvalidate cache (as in previous versions of knitr), you may associate it with a chunk option, e.g.,cache.extra = getOption('width'). The reason for this change is that it is too costly to invalidate the cache when thewidthoption changes---the effect of this option is only cosmetic and the code chunk output may not really rely on this option (thanks, @jaburgoyne, #1781).
MINOR CHANGES
-
is_html_output()returnsTRUEfor the Pandoc output formatgfmnow (thanks, @ttimbers @cderv, rstudio/rmarkdown#1756). -
plot_crop()no longer calls theconvertcommand in ImageMagick to trim non-PDF plots. Instead, the functionmagick::image_trim()is called. This means you no longer need to install ImageMagick, but should install the R package magick (thanks, @hpages, #1785). -
When the chunk option
fig.scapis used in R Markdown and the output format is LaTeX/PDF, the plot hookknitr::hook_plot_tex()will be used to create the appropriate figure environment. In previous versions,fig.scapis silently ignored (thanks, @billdenney, #1793).
knitr 1.26
NEW FEATURES
write_bib()also includes all citation entries in the package'sCITATIONfile if provided.
MINOR CHANGES
knit()no longer adjusts the global R optionwidth; previously it setsoptions(width = 75)by default.
knitr 1.25
NEW FEATURES
-
Office outputs (e.g.,
rmarkdown::word_document) supports the following chunk optionsout.width,out.height,out.extra. Their behavior follows the behavior of Pandoc'slink_attributesextention (thanks, @atusy, #1746). -
The chunk option
fig.processcan be specified by a function with theoptionsargument to read chunk options (thanks, @atusy, #1749). -
For
kable(format = 'latex'), a single string consisting ofl,c, andrfor thealignargument also works now, e.g.,knitr::kable(head(iris), 'latex', align = 'llcrr'). Previously it has to be a character vector of individual letters.
MAJOR CHANGES
- Reverted #1519 (which intended to fix #1487): the
valignargument ofkable(format = 'latex')meant to control the vertical alignment of the innertabularenvironment, instead of the floating position of the outertableenvironment. A separate argument namedpositionhas been added to control the floating position (e.g.,position = "!b").
MINOR CHANGES
- The returned value of
combine_words()is wrapped inxfun::raw_string()for pretty printing.
BUG FIXES
-
The
outputhook forrender_sweave()failed to respect the chunk optionresults='asis'(thanks, Achim Zeileis, https://stackoverflow.com/q/57571790/559676). -
Added the unit
pxto the chunk optionout.widthif its value is numeric (thanks, @chendaniely, #1761). -
The chunk option
dependsondid not work for non-R engines (thanks, @nielsrhansen, #1601).
knitr 1.24
MAJOR CHANGES
-
The
inputargument ofknitr::knit()must be a file path (a character string). It can no longer be connections. -
The
encodingargument ofknitr::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.
BUG FIXES
- Inline code chunk references are parsed as character vectors instead of single character strings separated by
\nnow. 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).
knitr 1.23
NEW FEATURES
-
Added
mogrifysupport inhook_png()andhook_mogrify()in order to obtain trimmed.pngfiles (thanks, @mhofert, #1697). -
It is possible to customize the sign
\timesused 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_codeand 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 optionsclass.*. For example,class.source = 'numberLines'is equivalent toattr.source = '.numberLines', butattr.sourcecan take arbitrary attribute values, e.g.,attr.source = c('.numberLines', 'startFrom="11"')(thanks, @atusy, #1710).
BUG FIXES
-
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 optionout.extrais not empty (thanks, @gabrielvazdemelo, #1691). -
When evaluating perl code chunks the interpreter is spawned with the
-Eoption, enabling all optional features such assay, rather than-e(thanks, @kiwiroy, #1699) -
When the chunk label of a
tikzchunk contains periods, thetikzoutput cannot be converted to the expected.svg(thanks, @ucpresearch, #1706). -
The
...argument forraw_latex()andraw_html()is actually passed toasis_output()now (thanks, @GregorDeCillia, #1716).
MAJOR CHANGES
-
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). Theencodingargument ofknitr::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 fromknitr::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.styis no longer bundled with the knitr package. This should only affect users who write.Rnwdocuments. Ifframed.styis 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.
knitr 1.22
NEW FEATURES
-
Added chunk options
class.error,class.warning, andclass.messageto customize the CSS classes for errors, warnings, and messages in R Markdown output, respectively (thanks, @gadenbuie, #1676). -
Added a new engine
sass/scssto convert Sass/SCSS to CSS using either the sass R package (LibSass) or Dart Sass executable (when R package not found, the engine optionengine.opts = list(package = FALSE), orengine.pathto executable is provided). After conversion, resulting CSS is treated as in the CSS engine (thanks, @emilyriederer, #1666). -
The
catengine supports the chunk optioneval = FALSEnow (thanks, @HanOostdijk, #1618). -
The chunk option
out.extracan be used to include extra attributes for the<iframe>generated fromknitr::include_url()orknitr::include_app()(thanks, @jvcasillas, #1648).
BUG FIXES
-
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
labeltokable()so that users can manually specify a label (thanks, @Inferrator, #1655). -
The chunk option
fig.show='hide'doesn't work forknitr::include_graphics()(thanks, @vincentarelbundock, #1675). -
The
tikzengine 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'andexternal = FALSEdidn't work in R Markdown (thanks, @martinschmelzer, #1649).
MAJOR CHANGES
-
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
encodingarguments inknitr::pandoc(),knitr::knit2pdf(),knitr2wp(), andknitr::Sweave2knitr(). The input files must be encoded in UTF-8. -
knitr::knit2html()still has theencodingargument, but it only supports UTF-8 internally.
MINOR CHANGES
-
Changed
tools::texi2dvi()totinytex::latexmk()for thetikzengine to compile TikZ graphics to other foramts (e.g.,svgorpng). 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).