Releases: yihui/knitr
CHANGES IN knitr VERSION 1.18
NEW FEATURES
-
added a new engine
julia
based onJuliaCall::eng_juliacall()
to support Julia code chunks (thanks, @Non-Contradiction, #1458) -
added a new chunk option
fig.dim
to specifyfig.width
andfig.height
using one option, e.g.,fig.dim = c(5, 7)
is a shorthand offig.width = 5, fig.height = 7
(thanks, @MichaelChirico, #1449) -
added two chunk options
fig.ncol
andfig.sep
to make it possible to arrange multiple subfigures in columns (thanks, @eliocamp, #1444) -
exported function
is_latex_output()
andis_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 functionnew_defaults()
(thanks, @yonicd, #1417) -
added another usage of
engine_output()
for expert users: if you are familiar with the list structure of theevaluate::evaluate()
output, you can let your custom engine return a similar list and callengine_output(options, out = YOUR_LIST)
(thanks, @kevinushey, #1442) -
added an
evaluate.inline
hook toknit_hooks
(thanks, @kevinushey, #1443)
MAJOR CHANGES
-
the
python
engine is based onreticulate::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 optionpython.reticulate = FALSE
(thanks, @kevinushey, #1440) -
the
auto_pdf
argument ofinclude_graphics()
defaults toFALSE
now; you can setoptions(knitr.graphics.auto_pdf = TRUE)
to change the default toTRUE
(thanks, @mebden, #1456)
BUG FIXES
-
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)
CHANGES IN knitr VERSION 1.17
MAJOR CHANGES
-
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 optioncache.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
andjs
, the source code will be displayed by default just like R code chunks, and you can hide the source code using the chunk optionecho = FALSE
(thanks, @skadauke, #1408) -
for
kable()
, thedigits
argument will be applied to columns of the classdifftime
(thanks, @RoyalTS, #1396)
BUG FIXES
-
when a table only has one column,
kable()
does not work in R Markdown documents (thanks, @expersso, yihui/printr#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)
CHANGES IN knitr VERSION 1.16
NEW FEATURES
-
adds two new options,
class.output
andclass.source
to apply additional HTML classes to output and source chunks, which can be useful for R Markdown documents with HTML output formats since you can define custom CSS styles for these classes (thanks, @ijlyttle #1335 and @AmeliaMN #1333) -
added a
sql.show_interpolated
chunk option forsql
engine. For{sql, sql.show_interpolated=TRUE}
, interpolated SQL query will be dispalyed in the renderred document instead (thanks, @saurfang, #1357) -
the chunk option
results=FALSE
is an alias ofresults='hide'
now (thanks, @hadley, #1360) -
added a wrapper function
knit2pandoc()
, and reStructuredText vignettes will be compiled through Pandoc instead of rst2pdf (thanks, @trevorld, #1386) -
longest common whitespace prefix in code chunks is now stripped off along with the eventual prefix (see #1391)
MAJOR CHANGES
-
a warning will be emitted when the chunk option
fig.show='hold'
and the output format is Word (rstudio/bookdown#249);fig.show='hold'
will be changed to'asis'
at the same time -
purl()
no longer writes verbatim non-R code chunks to the output R script; these code chunks will be commented out in the output -
purl()
can now also retrieve the code from inline expressions; it is disabled by default for compatibility, and can be enabled viaoptions(knitr.purl.inline = TRUE)
(thanks, @kforner, #1345) -
the chunk option
fig.show
also applies to plots included viainclude_graphics()
, e.g.fig.show='hold'
will put all plots to the end of a chunk (thanks, @statnmap, #1382)
BUG FIXES
-
kable()
should not ignore the table caption if provided when the input is a list, the table format ispandoc
, and the document output format is not HTML or LaTeX, e.g. Word output (thanks, @ugroempi, rstudio/bookdown#368) -
opts_chunk$set()
supports referencing asql
connection by variable name, e.g.knitr::opts_chunk$set(connection = "db")
(thanks, @javierluraschi, #1362) -
the chunk option
dev = 'CairoPS'
will lead to double filename extensions.eps.ps
(thanks, @qifei9, #1364) -
the output file of
write_bib()
is now encoded in UTF-8 (thanks, @arnyeinstein, #1374) -
the
<embed>
tag should be used instead of<img>
for PDF images in HTML output (thanks, Daijiang Li, http://stackoverflow.com/q/43549930/559676)
CHANGES IN knitr VERSION 1.15.1
NEW FEATURES
- added a new hook function
hook_pngquant()
that can callpngquant
to optimize PNG images (thanks, @slowkow, #1320)
BUG FIXES
- not really a knitr bug, but
knit_params()
should be better at dealing with multibyte characters now due to the bug fix in the yaml package vubiostat/r-yaml#6
CHANGES IN knitr VERSION 1.15
NEW FEATURES
NA
values can be displayed using different characters (including empty strings) inkable()
; you can set the optionknitr.kable.NA
, e.g.options(knitr.kable.NA = '')
to hideNA
values (#1283)- added a
fortran95
engine (thanks, @stefanedwards, #1282) - added a
block2
engine for R Markdown documents as an alternative to theblock
engine; it should be faster and supports arbitrary Pandoc's Markdown syntax, but it is essentially a hack; note when the output format is LaTeX/PDF, you have to define\let\BeginKnitrBlock\begin \let\EndKnitrBlock\end
in the LaTeX preamble - figure captions specified in the chunk option
fig.cap
are also applied to HTML widgets (thanks, @byzheng, rstudio/bookdown#118) - when the chunk option
fig.show = 'animate'
andffmpeg.format = 'gif'
, a GIF animation of the plots in the chunk will be generated for HTML output (https://twitter.com/thomasp85/status/785800003436421120) - added a
width
argument towrite_bib()
so long lines in bib entries can be wrapped - the inline syntax
`r#code`
is also supported besides`r code`
; this can make sure the inline expression is not split when the line is wrapped (thanks, Dave Jarvis) - provided a global R option
knitr.use.cwd
so users can choose to evaluate the R code chunks in the current working directory after settingoptions(knitr.use.cwd = TRUE)
; the default is to evaluate code in the directory of the input document, unless the knitr optionopts_knit$set(root.dir = ...)
has been set - if
options(knitr.digits.signif = TRUE)
, numbers from inline expressions will be formatted usinggetOption('digits')
as the number of significant digits, otherwise (the default behavior)getOption('digits')
is treated as the number of decimal places (thanks, @numatt, #1053) - the chunk option
engine.path
can also be a list of paths to the engine executables now, e.g., you can setknitr::opts_chunk$set(engine.path = list(python = '/anaconda/bin/python', perl = '/usr/local/bin/perl'))
, then when apython
code chunk is executed,/anaconda/bin/python
will be called instead of the system default (rstudio/rmarkdown#812) - introduced a mechanism to protect text output in the sense that it will not be touched by Pandoc during the conversion from R Markdown to another format; this is primarily for package developers to extend R Markdown; see
?raw_output
for details (which also shows new functionsextract_raw_output()
andrestore_raw_output()
)
MAJOR CHANGES
- the minimal version of R required for knitr is 3.1.0 now (#1269)
- the formatR package is an optional package since the default chunk option
tidy = FALSE
has been there for a long time; if you usetidy = TRUE
, you need to install formatR separately if it is not installed :set +m
is no longer automatically added tohaskell
code chunks (#1274)
MINOR CHANGES
- the package option
opts_knit$get('stop_on_error')
has been removed - the confusing warning message about
knitr::knit2html()
when buiding package vignettes using theknitr::rmarkdown
engine withoutpandoc
/pandoc-citeproc
has been removed (#1286) - the default value of the
quiet
argument ofplot_crop()
was changed from!opts_knit$get('progress')
toTRUE
, i.e., by default the messages from cropping images are suppressed
BUG FIXES
- the chunk option
cache.vars
did not really behave like what was documented (thanks, @simonKTH, #1280) asis_output()
should not be merged with normal character output whenresults='hold'
(thanks, @kevinushey, #1310)
CHANGES IN knitr VERSION 1.14
NEW FEATURES
- improved caching for Rcpp code chunks: the shared library built from the C++ code will be preserved on disk and reloaded the next time if caching is enabled (chunk option
cache = TRUE
), so that the exported R functions are still usable in later R code chunks; note this feature requires Rcpp >= 0.12.5.6 (thanks, @jjallaire, #1239) - added a helper function
all_rcpp_labels()
, which is simplyall_labels(engine == 'Rcpp')
and can be used to extract all chunk lables of Rcpp chunks - added a new engine named
sql
that uses the DBI package to execute SQL queries, and optionally assign the result to a variable in the knitr session; see http://rmarkdown.rstudio.com/authoring_knitr_engines.html for details (#1241) fig.keep
now accepts numeric values to index low-level plots to keep (#1265)
BUG FIXES
- fixed #1211:
pandoc('foo.md')
generates foo_utf8.html instead of foo.html by default - fixed #1236:
include = FALSE
for code chunks inside blockquotes did not work (should return>
instead of a blank line) (thanks, @fmichonneau) - fixed #1217: define the command
\hlipl
for syntax highlighting for Rnw documents (thanks, @conjugateprior) - fixed #1215: restoring
par()
settings might fail when the plot window is partitioned, e.g.par(mfrow = c(1, 2))
(thanks, @jrwishart @jmichaelgilbert) - fixed #1250: in the quiet mode,
knit()
should not emit the message "processing file ..." when processing child documents (thanks, @KZARCA)
MAJOR CHANGES
- knitr will no longer generate screenshots automatically for HTML widgets if the webshot package or PhantomJS is not installed
MINOR CHANGES
CHANGES IN knitr VERSION 1.13
NEW FEATURES
- code chunks that generate metadata may be cached now; it requires htmlwidgets >= v0.6 and htmltools >= 0.3.3 if you cache code chunks that contain HTML widgets or Shiny inputs/outputs (#1158)
- when the output format is not HTML, HTML widgets used to fail to render; now knitr will try to generate static screenshots for HTML widgets automatically using the webshot package; you can specify alternative screenshots via the chunk option
screenshot.alt
(which takes a character vector of image paths), and pass more options towebshot::webshot()
via the chunk optionscreenshot.opts
, e.g.list(delay = 3, cliprect = 'viewport')
- added two functions
include_url()
andinclude_app()
to embed URLs in the output (the latter is for Shiny app URLs); when the output format is HTML, iframe will be used; otherwise screenshots of the URLs will be used - screenshotting for HTML widgets and URLs can be forced for all output formats via the chunk option
screenshot.force = TRUE
; if you set the chunk optionscreenshot.force = FALSE
, knitr will just render these content normally and not take screenshots - added a new chunk option
fig.link
, which can be used to attach hyperlinks on figures, e.g. you can add a link to a screenshot of a Shiny app so that readers can check out the actual live app after clicking on the static screenshot (this chunk option currently only works for Markdown and LaTeX output) - syntactical errors in code chunks will be allowed when the chunk option
error = TRUE
and the package version of evaluate is at least 0.8.4; previously knitr would just stop on parsing errors (r-lib/evaluate#65) - PNG/JPEG images included via
include_graphics()
also respects the chunk optiondpi
now; if it is numeric and the chunk optionout.width
is not set, the output width (in inches) of an image will be automatically calculated from the actual width (in pixels) divided bydpi
; note this feature requires the packages png and/or jpeg to be installed, and you can disable the feature usingdpi = NA
(thanks, @hadley, rstudio/bookdown#38) - added a new hook function named
evaluate
inknit_hooks
so that users can redefine a evaluator to evaluate the code chunk; the default isevaluate::evaluate()
, and your custom evaluator must be compatible withevaluate::evaluate()
in terms of the argument names and the data structure of the returned value (a list of values with special classes) - added a new function
combine_words()
to combine multiple words / phrases into a single string, which may be useful in inline R expressions, e.g.combine_words(c('a', 'b', 'c'))
returnsa, b, and c
render_markdown()
gained a new argumentfence_char
to customize the character to be used as the code blocks fence, e.g. it can be a backtick, or a tilde, depending on the Markdown rendering engine (thanks, @tinyheero, #1161)- the
pandoc()
function no longer assumes Markdown input (thanks, @scls19fr, #1170) - added a new function
knit_meta_add()
so that users can manually inject metadata into the current knitr session - for the
tikz
engine, iffig.ext = 'svg'
,dvisvgm
will be called to convert the DVI output of TikZ to SVG; you need to installdvisvgm
, and Windows users have to install GhostScript as well (thanks, @dkilfoyle, #1177) - new
js
andcss
engines which surround their content with<script>
and<style>
tags respecitvely, and print no output when not in an HTML document - for LaTeX tables,
kable()
supports short captions now via thecaption.short
argument, e.g.kable(..., caption = 'A long caption', caption.short = 'A short caption')
(thanks, @ismayc, #1199) - added three global R options
knitr.sanitize.errors
,knitr.sanitize.warnings
, andknitr.sanitize.messages
to mask or change the messages, e.g. ifoptions(knitr.sanitize.errors = TRUE)
and the chunk optionerror = TRUE
, the actual error message will be replaced by a character string like"An error occurred"
; these options can also accept character values so you can customize the messages to be displayed, e.g.options(knitr.sanitize.warnings = 'You had a warning from the code')
; see rstudio/shiny#1123 for the motivation of these options
BUG FIXES
- when the chunk option
cache.rebuild = TRUE
, the cache database should be rewritten (thanks, Oleg Mayba) include_graphics()
did not work in inline R expressions (thanks, @WastlM, #1166)- the
cex
parameter was not correctly restored in the case ofopts_knit$set(global.par = TRUE)
(http://stackoverflow.com/q/35606445/559676) - for Rnw documents, when there are two instances of
\documentclass{}
, knitr might mistakenly treats the second instance as the the actual command to declare the document class (thanks, #1180, @ekstroem) - corrected the environment for evaluating R scripts in
stitch_rhtml()
andstitch_rmd()
(thanks, @Hughan, #1207)
MAJOR CHANGES
- the default value of the package option
eval.after
is changed fromNULL
tofig.cap
, i.e. the figure caption will always be evaluated after a code chunk is evaluated (thanks, @JoshOBrien, #1165) - the function
eclipse_theme()
has been removed since the website eclipsecolorthemes.org has been down for a long time
CHANGES IN knitr VERSION 1.12.3
BUG FIXES
- figures without captions may fail to render correctly in R Markdown v2
- fixed #1149: the
sanitize
andexternal
chunk options were not passed totikzDevice::tikz()
when thetikz()
device was opened to record plots in a chunk, so plots that contain special LaTeX characters would not work (thanks, @o-t)
CHANGES IN knitr VERSION 1.12
NEW FEATURES
- added a chunk option
fig.asp
to specify the aspect ratio (i.e. the ratio height/width) of figures: whenfig.asp
is specified, the height of a figure (the chunk optionfig.height
) is calculated fromfig.width * fig.asp
- added a new function
knit_watch()
to knit input files continously when any of them are updated, so you do not have to call a knitting function likeknit()
,knit2pdf()
, orrmarkdown::render()
repeatedly as you update an input document kable()
supports generating multiple tables from a list of data objects, and the tables will be placed side by side when the output format is HTML or LaTeX- the
format
argument ofkable()
can be a function that returns a character string of the table format (thanks, @haozhu233, #1132) - added a new function
include_graphics()
to embed existing image files into knitr documents; see?include_graphics
for details - added a new object
opts_hooks
that can be used to set up chunk option hooks to modify chunk options; see?opts_hooks
for details (thanks, @hadley, #1096) - added a chunk option
ffmpeg.bitrate
(default:1M
) to control the quality of WebM videos created from FFmpeg (thanks, @JsonPunyon, #1090) - added a chunk option
ffmpeg.format
(default:webm
) to control the video format of FFmpeg; this option specifies the filename extension of the video (#712) - plots drawn by
tikzDevice
are also measured and recorded with that device (thanks, @krlmlr, #1066) - for the chunk option
out.width
, a value of the formxx%
will be converted toxx/100\\linewidth
when the output format is LaTeX, so we can specify figure widths as percentages for both LaTeX and HTML output - for the chunk option
background
(to define the background color of code chunks in Rnw documents), the valueNA
means knitr will no longer write\definecolor{shadecolor}
to the output of an individual code chunk (you can also enable this behavior by setting it as a global chunk option) (thanks, @friendly, #1122) - added a new engine
block
to wrap the chunk in a LaTeX environment or an HTMLdiv
, depending on the output format; the name of the environment or the class of thediv
can be specified via the chunk optiontype
- you can use the
svglite
device in the svglite package (https://github.com/hadley/svglite) via the chunk optiondev = 'svglite'
cache = TRUE
works better for thestan
engine now: the Stan model object will be saved and can be loaded the next time for the cached code chunk (thanks, @dalewsteele, #1064)- the chunk option
engine.env
can be used to set environment variables when running engines likebash
; this option is passed to theenv
argument ofsystem2()
(thanks, @mbojan, #1032)
BUG FIXES
- the
asis
engine did not preserve line breaks in the code chunk kable()
could not display chron objects correctly (thanks, @liesb, #1118)kable(format = 'latex', longtable = TRUE)
did not write the table caption in the correct place (should be inside thelongtable
environment)- fixed #1055: the
tikz
device may fail if there are code chunks before\documentclass{}
in Rnw documents (thanks, @ClaudiusL) - fixed #1119: when the chunk option
engine != 'R'
, thesize
option does not work (thanks, @cysouw)
MAJOR CHANGES
- local chunk options can override options set in
opts_template
now, e.g. foropts_template$set(quiet = list(echo = FALSE))
, and a local chunk optionecho = TRUE
will overrideecho = FALSE
inopts_template
for the current code chunk (thanks, @aaronwolen, #1140)
MINOR CHANGES
PDF Documentation
Here is the knitr documentation, mainly the PDF documents compiled from the examples directory: https://github.com/yihui/knitr/tree/master/inst/examples Unless explicitly stated, the documents are always compiled with the development version of knitr.