-
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_attributes
extention (thanks, @atusy, #1746). -
The chunk option
fig.process
can be specified by a function with theoptions
argument to read chunk options (thanks, @atusy, #1749).
- The returned value of
combine_words()
is wrapped inxfun::raw_string()
for pretty printing.
- The
output
hook forrender_sweave()
failed to respect the chunk optionresults='asis'
(thanks, Achim Zeileis, https://stackoverflow.com/q/57571790/559676).
-
The
input
argument ofknitr::knit()
must be a file path (a character string). It can no longer be connections. -
The
encoding
argument 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.
- Inline code chunk references are parsed as character vectors instead of single character strings separated by
\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 inhook_png()
andhook_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 optionsclass.*
. For example,class.source = 'numberLines'
is equivalent toattr.source = '.numberLines'
, butattr.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 optionout.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 assay
, rather than-e
(thanks, @kiwiroy, #1699) -
When the chunk label of a
tikz
chunk contains periods, thetikz
output 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).
-
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). Theencoding
argument 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.sty
is no longer bundled with the knitr package. This should only affect users who write.Rnw
documents. Ifframed.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
, andclass.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 optionengine.opts = list(package = FALSE)
, orengine.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 optioneval = FALSE
now (thanks, @HanOostdijk, #1618). -
The chunk option
out.extra
can be used to include extra attributes for the<iframe>
generated fromknitr::include_url()
orknitr::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
tokable()
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
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'
andexternal = 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 inknitr::pandoc()
,knitr::knit2pdf()
,knitr2wp()
, andknitr::Sweave2knitr()
. The input files must be encoded in UTF-8. -
knitr::knit2html()
still has theencoding
argument, but it only supports UTF-8 internally.
-
Changed
tools::texi2dvi()
totinytex::latexmk()
for thetikz
engine to compile TikZ graphics to other foramts (e.g.,svg
orpng
). 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 optiontidy = TRUE
meanstidy = 'formatR'
and still usesformatR::tidy_source()
to reformat the code. The chunk optiontidy
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 mayinstall.packages('gifski')
and set the chunk optionanimation.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()
, andraw_html()
to wrap content in raw attribute blocks for Pandoc (thanks, @hughjonesd, #1633).
-
valign
inkable_latex()
does not put the float alignment to the correct location (thanks, @haozhu233, #1487, #1519). -
engine.path
does not work forengine = 'dot'
(thanks, @billy34, #1534). -
The
sql
engine now caches the result properly when the chunk optionoutput.var
is specified (thanks, @yutannihilation, #1544). -
knit_params()
mangles UTF-8 text not representable in current locale (thanks, @kevinushey, #1557). -
The
linesep
argument inkable(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 registerknit_print
methods defined in code chunks. For package authors, it no longer suffices to export a method without importingknitr::knit_print
, but if you don't want to import it, there is still a workaround. See the package vignettevignette('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).
- Added a
roxygen_comments
parameter toread_chunk()
in order to control whether trailing commentary is stripped from code chunks; default behaviour is to keep roxygen comments withroxygen_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 optiondev = 'tikz'
to PDF, which means you have to install the tinytex package if you use this device. -
Similarly,
tinytex::latexmk()
is used inknit2pdf()
andstitch()
.
-
Fixed rstudio/bookdown#501: the chunk option
out.height
can also take a percentage value when the output format is LaTeX (similar toout.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 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 the 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)
-
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 behaviour (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)
-
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 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)
-
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)
-
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
go
engine (thanks, @hodgesds, #1330) -
added a
sql.show_interpolated
chunk option forsql
engine. For{sql, sql.show_interpolated=TRUE}
, interpolated SQL query will be displayed in the rendered 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)
-
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)
-
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)
- added a new hook function
hook_pngquant()
that can callpngquant
to optimize PNG images (thanks, @slowkow, #1320)
- 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
-
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()
)
-
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)
-
the package option
opts_knit$get('stop_on_error')
has been removed -
the confusing warning message about
knitr::knit2html()
when building 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
-
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)
-
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 labels 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)
-
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)
- knitr will no longer generate screenshots automatically for HTML widgets if the webshot package or PhantomJS is not installed
-
if
dev = 'cairo_pdf'
, thecairo_pdf
device will be used to record plots (previously thepdf
device was used) (#1235) -
LaTeX short captions now go up to the first
.
,:
or;
character followed by a space or newline (thanks, @knokknok, #1249)
-
kable
now accepts a single multi-character string for alignment, sokable(..., align=c('c','l'))
can be shortened tokable(..., align='cl')
-
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 an 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 respectively, 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
-
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 treat the second instance as 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)
-
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
-
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)
-
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 continuously 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)
-
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)
- 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)
-
added an argument
force_v1
toknit2html()
; when it isTRUE
,knit2html()
renders the input file as an R Markdown v1 document even if it is for R Markdown v2 (#1130) -
the trailing space after
![]()
(for plots) in Markdown output has been removed (#1049)
-
added an argument
format.args
tokable()
to pass arguments toformat()
mainly to format numeric values, e.g. you can use,
as the thousands separator viakable(..., format.args = list(big.mark = ','))
(thanks, @neuwirthe, #1086) -
added an argument
quiet
toplot_crop()
(thanks, @WastlM, #1034) -
added
!expr
and!r
support in YAML forknit_params()
(#1069) -
added two language engines
mysql
andpsql
(thanks, @beanumber, #1076)
-
the two hook functions
hook_rgl()
andhook_webgl()
have been moved from knitr to the rgl package (v0.95.1247) (thanks, @dmurdoch) -
inline R expressions will always be evaluated; previously, they were not be evaluated if the global chunk option
eval = FALSE
, and the inline output was??
(thanks, @Bozh, #1046)
- the HTML code generated for FFmpeg animations did not work through Pandoc conversion (thanks, @s-fiebig, #1067)
- this version is a patch release due to a few changes in handling the
params
field of the YAML metadata, including- the character input passed to
yaml::yaml.load()
will always be converted to UTF-8 to make sure multibyte characters work in YAML - the character output from
yaml::yaml.load()
will always be marked as UTF-8 (vubiostat/r-yaml#6) y
,Y
,n
, andN
will not be treated as booleans (TRUE
/FALSE
), although they do stand for booleans in the YAML 1.1 spec- for
purl()
, theparams
field will be correctly written to the R script
- the character input passed to
-
added a new chunk option
cache.rebuild
(default:FALSE
) to force knitr to invalidate and rebuild the cache for a chunk whencache.rebuild = TRUE
(thanks, @zachary-foster, #995) -
added a
stata
engine and improved the existingsas
engine (thanks, @Hemken #979, @muschellij2 #984) -
the Markdown table generated from
kable()
will use the width of characters to decide how many spaces are needed for padding, which can be useful for wide characters such as CJK characters (normally of width 2 per char) (thanks, @yutannihilation, #985) -
for language engines, the syntax of R Markdown code chunk headers can be
```{lang, option=value}
now (e.g.```{python}
and```{Rcpp}
), which is equivalent to```{r, engine='lang', option=value}
(thanks, @JanSchulz, #963) -
added the
...
argument toall_labels()
to make it possible to filter chunk labels according to local chunk options, e.g. you can useall_labels(engine == 'Rcpp')
to find the labels of all code chunks that have the chunk optionengine = 'Rcpp'
, and pass the character vector of labels toref.label
to gather allRcpp
code chunks into a single chunk -
added a new function
knit_params()
to extract report parameters from the YAML metadata of R Markdown documents; see?knit_params
for details (thanks, @jjallaire, #997) -
added support for code chunks inside Markdown blockquotes; see the example below (thanks, @r-gaia-cs, #1022)
> Here is a quote, followed by a code chunk: > > ```{r} > x = 1:10 > rev(x^2) > ```
-
the function
current_input()
gained a new argumentdir = FALSE
; whendir = TRUE
, the absolute path of the input document is returned (thanks, @klmr, #950) -
if you set
options(knitr.duplicate.label = 'allow')
before callingknit()
, duplicate labels will be allowed, and an incremental suffix will be appended to the duplicate label, e.g. when there are two non-empty chunks with the same labelfoo
, the second label may be converted tofoo-2
automatically; please use this feature only if you understand the consequences (e.g. the plot generated by a chunkfoo
might befoo-2-1.pdf
, which can be surprising) (thanks, @khughitt, #957) -
added a new language engine named
lein
to support Clojure (thanks, @kindlychung, #940)
- the minimal required version of R is 3.0.2 now, and you are recommended to use the latest version of R when possible
-
fixed #942: the package option
opts_knit$get('base.dir')
does not work when the chunk optionopts_chunk$get('fig.path')
contains a directory (thanks, @daattali and @cheebingloh) -
fixed the bug reported at http://stackoverflow.com/q/28954647/559676 (
dev = 'png'
failed to work with rmarkdown when the output format ispdf_document
)
-
added a new function
load_cache()
so that we can read an object from a cached code chunk, even if the chunk appears later in the document and the object needs to be used earlier; see the example #114 at https://github.com/yihui/knitr-examples (related to #868) -
added a new function
clean_cache()
to clean up the cache files that are probably no longer needed, e.g. after you rename or delete cached code chunks (thanks, @sjmgarnier, #933) -
knit2wp()
can update an existing post or create a page now (thanks, @jaredlander, #916, #917) -
added an engine
stan
to support Stan through the rstan package; see http://rpubs.com/jrnold/knitr-stan for an example (thanks, @jrnold, #903) -
for the
tikz
engine, the path to theconvert
utility of ImageMagick can be specified via the chunk optionengine.opts
, e.g.engine.opts = list(convert = 'path/to/convert')
(thanks, @mienkoja, #897) -
similarly, more command line arguments to
convert
can be specified via, for example,engine.opts = list(convert.opts = '-density 300')
(#896)
-
when the chunk option
dev = 'png'
,grDevices::png()
is used to record plots, instead of the default PDF null device (thanks, @yixuan, #729) -
currently, R (3.1.2) does not really pass the vignette encoding to vignette engines (which is probably a bug), and knitr vignette engines will assume UTF-8 is the file encoding
-
when the chunk option
tidy=FALSE
, andeval
takes a numeric vector, it used to mean the line numbers of the code chunk; now it means the indices of the R expressions in the code chunk, regardless oftidy=FALSE
orTRUE
(yihui/knitr-examples#39, thanks, @isomorphisms)
-
you need to upgrade the rgl package to at least v0.95.1201 if you use the hook function
hook_webgl()
(thanks, @dmurdoch, #901) -
for the automatically generated figure caption and label of a figure, the label is placed outside of the caption now, i.e. the format was changed from
\caption{\label{}}
to\caption{}\label{}
(thanks, @dr-moebius, @krlmlr, @ltorgo, #746)
-
fixed #898:
kable()
did not work on matrices with duplicate row names (thanks, @tomaskrehlik) -
fixed #927:
kable()
did not work for matrices of zero row and/or zero column (thanks, @hadley) -
fixed #929:
opts_knit$restore()
does not restore theanimation.fun
option (thanks, @julian-gehring)
-
when using knitr with the rmarkdown package, the internal output hook for plots will be automatically switched to the LaTeX plot hook when necessary; for example, when the chunk options fig.align, out.width, out.height, and/or out.extra are specified, raw LaTeX code will be generated to align/set the size of plots, because there is no support for figure alignment or setting the size in the native Markdown syntax; for Word output, these options are simply ignored (related issues: #626, rstudio/rmarkdown#86, rstudio/rmarkdown#148, rstudio/rmarkdown#303)
-
added a new function
fig_chunk()
to provide a public API to get the figure filenames produced from code chunks; since knitr 1.7 changed the figure file numbering scheme, it broke documents with hard-coded figure filenames, e.g. for Rnw documents,\includegraphics{foo.pdf}
should be\includegraphics{foo-1.pdf}
after knitr 1.7, and such problems can be avoided by\includegraphics{\Sexpr{fig_chunk('foo', 'pdf')}}
(thanks, @edwardabraham, #870) -
added an argument
escape = TRUE
tokable()
to escape special characters in LaTeX and HTML tables (thanks, @juba, #852) -
added a new function
knit_filter()
to filter out code chunks and inline R expressions; this function can be used as the filter for the spell check functionutils::aspell()
; see?knit_filter
for examples (#581) -
added a new function
spin_child()
to spin child R scripts when wespin()
a main script (thanks, @krlmlr, #621) -
added a new function
inline_expr()
to help authors write the "source code" of the inline expression, e.g.inline_expr('1+1')
generates`r 1+1`
in R Markdown documents (#890) -
the cache will attempt to preserve the order in which packages are stored on the search path (thanks, @dgrtwo, #867)
-
added a new argument
table.envir
tokable()
for LaTeX tables only; if the table caption is specified (notNULL
), the LaTeX environmenttable
will be used by default (i.e. the table is generated in\begin{table} \end{table}
), and you can specify alternative environments viakable(..., table.envir = '???')
(thanks, @dalupus, #872) -
chunk options are supported using the syntax
# ---- label, options ----
in the R script passed tostitch()
(thanks, @wibeasley, yihui/knitr-examples#35) -
syntax highlighting for .Rnw and .Rhtml documents can be further customized by setting
opts_knit$set(highr.opts = list(markup = cmd_mine))
wherecmd_mine
is a data frame for themarkup
argument ofhighr::hilight()
(thanks, @lq, #869) -
added a new language engine
groovy
(thanks, @vveitas, #876)
-
fixed #862: the YAML metadata in child R Markdown documents was not correctly removed (thanks, @krlmlr)
-
fixed #874: for the engines
dot
andtikz
, the figure directory will be created recursively (thanks, @WilDoane) -
fixed #654: sub figures were not aligned correctly in LaTeX when the chunk option
fig.align
was specified (thanks, @lionandoil) -
the vignette engine
knitr::rmarkdown_notangle
did not really work (thanks, @bbolker, http://stackoverflow.com/q/26726388/559676)
-
added a simple Fortran engine after sitting with John Nash for a few minutes at UseR!2014; now we can use the chunk option
engine = 'fortran'
to include Fortran code in a source document, which will be compiled and loaded viaR CMD SHILIB
anddyn.load()
, respectively -
added vignette engines with the suffix
_notangle
, which have the same weave functions as those engines without this suffix but have disabled the tangle function, meaning there will not be R scripts generated from the vignettes duringR CMD build
orR CMD check
(thanks, Carl Boettiger and Michael Koohafkan, #784) -
added an argument
col.names
tokable()
, so we can specify different column names (thanks, @jackflibb, #801) -
added a new output hook called
text
, and its default valueknit_hooks$get('text')
is the identity functionfunction(x) x
; this hook is applied to the text chunks (recallknit_hooks$get('chunk')
is applied to code chunks) -
added a chunk option
fig.showtext
to support the showtext package; iffig.showtext = TRUE
(which is what you should do if you use the showtext package),showtext::showtext.begin()
is called before drawing plots (thanks, @yufree, #799) -
added a new language engine
node
for Node.js (thanks, Jake Burkhead, #823) -
added a package option
global.par
; if we setopts_knit$set(global.par = TRUE)
(by default it is FALSE), thepar()
settings from the last code chunk will be preserved and applied to the next code chunk (thanks, Jim Winget) -
language engines also write error messages (if there are any) in the output now (thanks, Fabian Hirschmann, #789)
-
added the
envir
argument toknit_child()
so that users can specify a different environment to evaluate the child documents (thanks, Stéphane Laurent, http://stackoverflow.com/q/24009622/559676) -
for
set_parent()
, the lines in the parent document that start with\bibliography
are matched and inserted in the child document so LaTeX bibliography also works for the child document (thanks, Mark Heckmann, #819) -
for the chunk option
engine = 'cat'
, the code chunk can be displayed in the output if the chunk language is specified viaengine.opts
, e.g.engine.opts = list(lang = 'makefile')
-
fixed #779: when the chunk options
tidy=FALSE
andeval=FALSE
,prompt=TRUE
did not work for R expressions of multiple lines (thanks, Qijie Zhao) -
fixed #788: there was no increment in the chunk counter when the code chunks were read through
read_chunk()
, which may lead to clashes of chunk labels (thanks, Jason Ackman) -
fixed #790: when chunk A reuses code from chunk B via
<<B>>
, and only the first line of B is empty, chunk reuse can fail because A sees B as empty (thanks, @kingaa) -
fixed #791: if one has specified the chunk option
dev.args
, onlypointsize
andbg
in it can be passed to the default recording device (thepdf()
device) (thanks, @M-Russell and @joelgombin) -
fixed #822:
cache.lazy = FALSE
did not really work (thanks, Liz Ing-Simmons) -
fixed rstudio/rmarkdown#205: when R marks the encoding of the input document as latin1,
knit()
can fail to convert its encoding (thanks, @ripkrizbi) -
fixed #828: scientific notation for inline numbers did not work in R Markdown v2 when the output format is LaTeX (thanks, @nacnudus)
-
fixed #833: for the LaTeX output format, when
fig.cap
contains.
in{}
, the automatic short caption does not work (thanks, Roman Luštrik) -
fixed #844: when the
digits
argument is a vector andx
is a numeric matrix,kable(x)
did not work (thanks, @dmenne, #844)
-
the
knit()
function no longer modifies R's defaultoptions(digits)
from 7 to 4, since it may lead to confusion especially when printingsummary()
output; for those who want the old behavior, you must setoptions(digits = 4)
at the beginning of your document (thanks, John Honaker, #777) -
the figure file numbering scheme has changed: for a chunk with a label
foo
, its figure files are named asfoo-i
wherei
ranges from1
ton
(the total number of plots in this chunk); previously, the figure file was named asfoo
instead offoo-1
when there was only one plot generated in this chunk, which has a potential bug: consider two chunks namedfoo
andfoo2
, respectively;foo
generates two figuresfoo1.png
andfoo2.png
, andfoo2
generates one figurefoo2.png
, which will overwrite the second figure generated from the chunkfoo
(thanks, @kevinushey, @kohske, @kforner, #704, #832) -
for warnings and errors from code chunks, the call that produced them will be printed as part of the message, e.g. previously an error might just be
Error: x must be positive
, and now it may beError in FUN(x = -1): x must be positive
(thanks, @jennybc, #846) -
for the engine
coffee
(CoffeeScript), the flag-p
has been removed from the command line arguments, which means the default behaviour of this engine is to evaluate the code, instead of printing JavaScript; if you want the old behaviour, you need the chunk optionengine.opts = '-p'
(thanks, Jake Burkhead, #821) -
when the chunk option
results = 'hold'
, the text output blocks will be collapsed into a single block (thanks, Gavin Simpson, #798) -
the video format for animations (when the chunk option
fig.show='animate'
) was changed from OGG to WebM (http://www.webmproject.org), which has many benefits over other formats, especially for the web (thanks, @gaorongchao, #641) -
the YAML metadata in Markdown child documents will be ignored (only the metadata in the top parent document is preserved)
-
scientific formatting for inline R output is only applied to objects of which the first class is
numeric
, e.g.chron::chron()
objects will no longer be formatted using scientific notations (thanks, @sanfordweisberg, #806) -
for R Markdown v2 documents, if the inline R output is formatted using the scientific notation, the output must be put in a math environment, e.g.
$`r 2e10`$
-
added Textile (http://txstyle.org) support thanks to Richard Cotton; see the example 105 at https://github.com/yihui/knitr-examples (#623)
-
added an argument
inline
tospin()
so that some R code (by default, code of the form{{code}}
) can be treated as inline expressions (thanks, Kirill Müller, #620) -
added an argument
prefix
towrite_bib()
so that we can customize the prefix for bib entries; we can also setoptions(knitr.bib.prefix = 'a_string')
so thatwrite_bib()
uses this global option as the default value forprefix
(thanks, Michael Friendly) -
the chunk option
dev.args
will be passed to thepdf
recording device ifpdf
is also in the chunk optiondev
(note the recording device can be different with the actual drawing device); for example, you can pass a differentpointsize
to the PDF recording device (thanks, Felix Klein) -
intermediate files generated during
spin()
are deleted by default, this can be overridden by setting the new parameterprecious
toTRUE
(thanks, Kirill Müller, #628) -
exposed the previously internal chunk option
code
, which is used to store the source code of a chunk; now users also have control over this option, which means we can programmatically assign source code for a code chunk, e.g.code = capture.output(dump('fivenum', ''))
-
added a new chunk option
collapse
for Markdown output; ifcollapse = TRUE
, knitr will try to merge the source and output blocks into one block; see example 039 at https://github.com/yihui/knitr-examples (thanks, Hadley Wickham) -
added a new chunk option
fig.retina
for better display quality of images in HTML output; for example, the physical size of an image is doubled and its display size is halved whenfig.retina = 2
-
added a new chunk option
strip.white
to trim the white lines in the beginning or end of a source chunk in the output (strip.white = TRUE
by default) -
added a new chunk option
render
for custom rendering of R objects in the output; by default, the render function isprint()
(orshow()
for S4 objects) (thanks, Milan Bouchet-Valat, #484) -
added a new S3 generic function
knit_print()
, which is used as the default printing function for R objects in the code output now; users can define custom S3 methods to change the printing behaviour of R objects in knitr -
added a new engine
scala
for Scala thanks to Simeon Fitch (#640) -
added a new engine named
asis
to write the chunk content without processing it; it also respects the chunk optionsecho
andeval
-- when either one isFALSE
, the chunk will be hidden; this makes it possible to write text conditionally (thanks, Simon, #622) -
the Haskell engine supports multiline clauses using
:set +m
now, thanks to Adam Vogt (#633) -
added a new hook function
hook_purl()
so that code can be more reliably extracted from input documents; see?hook_purl
for details (#607) -
exported a function
plot_crop()
which was used inhook_pdfcrop()
in previous versions to crop the white margin of plots -
added a new chunk option
cache.lazy
(TRUE/FALSE) to decide whether to save and lazy load objects whencache
is enabled; for really large objects, you may needcache.lazy=FALSE
(thanks, Dario Strbenac, Scott Simpkins, and Mattrition, #572) -
added a chunk option
cache.comments
(TRUE/FALSE) to decide whether updating R comments in a code chunk should invalidate the cache database (thanks, @knokknok, #718) -
kable()
supports alignment for HTML tables now (thanks, Joseph Larmarange, #656 and #683) -
kable()
supports table captions in LaTeX, HTML and Pandoc's Markdown now (thanks, Joseph Larmarange, #687) -
the
digits
argument forkable(x)
can also be a vector of lengthncol(x)
, in which case the number of digits is set for each column separately, e.g.kable(data.frame(x=rnorm(10), y=rnorm(10)), digits = c(1, 4))
(thanks, @nacnudus, #771) -
for Markdown tables,
kable()
gained a new argumentpadding
to specify the inner padding of table cells using spaces (thanks, @gavril0, #699) -
added a new vignette engine called
rmarkdown
, which usesrmarkdown::render()
to create a package vignette from an R Markdown document; see http://rmarkdown.rstudio.com for more information about the rmarkdown package, and the vignetteknit_print.Rmd
in knitr for an example (basically you specify\VignetteEngine{knitr::rmarkdown}
in your vignette) -
indentation is preserved when using chunk references
<<>>
, i.e., if<<>>
is indented, the spaces before it will be applied to the code that it refers to (thanks, Terry Therneau) -
added a chunk option
fig.process
, which can be set as a function to take the path of a plot and process it, e.g.fig.process = function(x) knitr::plot_crop(x)
; note that thefig.process
function must return a character string, such as the path of the figure, which might have been changed inside the function -
added a chunk option
R.options
so that we can temporarily set local options() for the current code chunk, and the options will be restored after the chunk (thanks, @r2evans, #764) -
the argument
shortcode
inknit2wp()
can take a logical vector of length 2 now; the first element determines whether to highlight source code, and the second decides syntax highlighting for text output (thanks, Derek Ogle, #663) -
Sweave2knitr() will report the line numbers indicating where the Sweave-specific syntax was used (thanks, Kirill Muller, #676)
-
added a function
current_input()
to return the filename of the input document (thanks, Kate Davis, #701) -
for Markdown, if n (n >= 3) backticks are detected in the code output, the output will be wrapped in n+1 backticks to make sure the original backticks in the output are not interpreted as the token of fenced code blocks
-
for a chunk hook function, we can use a fourth optional argument
name
, which takes the value of the hook name, e.g. forknit_hooks$set(foo = hook_foo)
,hook_foo
can be of the formfunction(before, options, envir, name)
, wherename == 'foo'
(thanks, Thell Fowler, #733) -
all the four arguments
before
,options
,envir
, andname
for a chunk hook are optional now, e.g. you can define a hook function of the formfunction(before, options)
,function(before, name, envir)
, and so on -
added two read-only chunk options
out.width.px
andout.height.px
, which are the numbers of pixels calculated fromfig.width
andfig.height
(which have units in inches), respectively, and the chunk optionsout.width
andout.height
can override the calculated natural size -
added a new argument
encoding
to thepandoc()
function to specify the character encoding of the input file(s) (fixed the problem http://stackoverflow.com/q/22198832/559676)
-
due to the change in evaluate v0.5, evaluate() may return the raw values of expressions, but the S3 method wrap() does not know how to handle them; now these values are just ignored (thanks, Dan Tenenbaum)
-
fixed a bug for dep_auto() that may occur if old cache files generated from previous versions of knitr are used (thanks, Jeffrey Racine)
-
fixed the bug reported at http://stackoverflow.com/q/19166724/559676: the inline hook did not work well with non-numeric values, e.g. Date (thanks, Waldir Leoncio)
-
infinity is formatted as a symbol in inline LaTeX and HTML modes (thanks, Kirill Müller, #629)
-
kable()
did not keep the row name when the data only has one row (thanks, @eev2, #636) -
kable()
did not recycle thealign
argument correctly (thanks, Adam Cooper, #638) -
kable()
chokes on tables with NA's (thanks, Harlan Harris and Benjamin Schiller, #720) -
kable()
did not work with non-numeric data frames (thanks, @talexand, #702) -
for Markdown/reST tables,
kable()
should make sure there are at least one empty line before the table output (thanks, @talexand, #705) -
fixed a bug related to child documents -- chunk options passed from a parent document may not be restored after the child document exits (thanks, Frank Harrell, http://bit.ly/17yitsD)
-
fixed a bug for
hook_rgl()
when the chunk optiondev
is a vector of length greater than one (thanks, Ashley Manton, #703) -
hook_rgl()
did not work with the chunk optionfig.cap
(thanks, Kohske Takahashi, #700) -
%\documentclass{}
was mistakenly treated as the specification of the document class instead of a comment in a LaTeX document (thanks, Jarad Niemi, #713)
-
the default value for the chunk option
tidy
isFALSE
now, which means the R source code in chunks will no longer be reformatted byformatR::tidy.source()
by default; this feature must be explicitly turned on bytidy=TRUE
, and it has brought a lot of confusion in the past, so it is perhaps a good idea not to reformat the source code by default -
now we treat the closing mark (e.g.
@
in Sweave or the three backticks in R Markdown) as part of the code chunk, instead of the beginning of a text chunk, and a consequence for this change is that knitr no longer adds blank lines to the beginning of the text chunks (thanks, Thell 'Bo' Fowler, #752) -
inline R expressions will no longer be evaluated in
try()
, which means errors in inline R code will be emitted immediately -
the first argument of the
plot
hook is the filename of the plot now; in previous versions, it was a vector of length 2 (basename and file extension); see?hook_plot
-
the default value for the
format
argument inpandoc()
has changed: it defaults to thet
field in the configuration if found, otherwise, it defaults to'html'
(thanks, Kohske Takahashi, #697) -
in the previous version, we can set
options(knitr.foo = value)
so that knitr can adjust the package optionsopts_knit$set(foo = value)
before knitting a document; now the prefix for package options has been changed toknitr.package.
, i.e. we should setoptions(knitr.package.foo)
to achieveopts_knit$set(foo)
; besides, it is also possible to change the default chunk options usingoptions(knitr.chunk.foo)
now, but you are warned that this may bring reproducibility issues, so please use with care
-
for R Markdown/AsciiDoc, line breaks are allowed in the inline R expressions now (thanks, Andrew MacDonald, #655)
-
for AsciiDoc input, the R inline expressions can be written using the same syntax as R Markdown, i.e.
r expression
-
numbers containing characters other than digits 0-9, periods or commas are formatted as math in inline LaTeX, for negative numbers, infinity symbol, corner cases such as
10^{n}
, ... (thanks, Jeffrey Racine and Kirill Müller, #635) -
the column name
id
for row names in thekable()
output is removed when the output format is Markdown (thanks, Artem Klevtsov, http://stackoverflow.com/q/19875529/559676) -
for R Markdown, special characters in figure filenames are no longer replaced by
_
, since RStudio v0.98.490 has fixed the base64 encoding bug; please upgrade RStudio to the latest version: http://www.rstudio.com/ide/download/ -
the
tikzMetricsDictionary
option (for the tikzDevice package) is no longer overridden if it has already been set inoptions()
(thanks, @rmatev, #708)
-
a new option value
results='hold'
to flush all text output to the end of a chunk likefig.show='hold'
(thanks, Harlan Harris, #593) -
when cache is enabled, automatic chunk dependencies can be truly automatic now; there is no need to call
dep_auto()
explicitly, and all we need to do is the chunk optionautodep=TRUE
; the chunk dependencies will be rebuilt after each chunk, so when new chunks are inserted into the document, knitr can also figure out the new dependencies automatically (thanks, @knokknok, #592) -
for Sublime Text users, there is a SublimeKnitr package to support LaTeX and Markdown with knitr; thanks, Andrew Heiss (#449) (this is not really a new feature of knitr itself, though)
-
now the chunk options
warning
andmessage
can also take numeric values as indices to select which warnings/messages to include in the output (thanks, Simon Urbanek, #590)
-
code changes in chunks should invalidate the cache when the chunk option
cache < 3
; fixed by @knokknok in #587 -
fixed the bug reported at http://stackoverflow.com/q/18302179/559676; before evaluating inline R code, the chunk options
eval
must be evaluated to a logical value -
fixed the bug reported at http://stackoverflow.com/q/18544045/559676; read_chunk() no longer excludes code without chunk headers, so stitch() will include all the code as expected
-
fixed the bug reported under http://stackoverflow.com/a/18541083/559676; now
\ensuremath{}
can be correctly applied to numbers of the form10^{-n}
-
fixes a regression bug reported by Graham Williams: https://groups.google.com/forum/#!topic/knitr/_I5rlo9tOeA the global chunk options set in child documents are no longer restored
-
fixed #604:
kable()
did not work on data frames/matrices of one row (thanks, Kevin Ushey) -
fixes the bug reported at http://stackoverflow.com/q/18992260/559676;
render_jekyll('prettify')
should have pasted the source code lines into one character string
- when the chunk option
cache=2
, the recorded plots (i.e. display lists) will no longer be cached, and the figure files will be assumed to exist the next time the document is compiled, otherwise the cache will be purged and the chunk needs to be recomputed; this will save some disk space and avoid bugs like #588 (thanks, @knokknok)
-
the Rnw chunk syntax is more tolerant on chunk headers in the sense that any characters after
<<>>=
are discarded, e.g.<<echo=TRUE>>===foo
will be treated as<<echo=TRUE>>=
(thanks, Michael Friendly) -
knitr:::.onLoad()
no longer modifies thePATH
variable when/usr/texbin
is not inPATH
under Mac OS -
when a message/warning/error contains line breaks, they are preserved and the message will not be re-wrapped (#602, thanks, Tyler Rinker)
-
read_chunk()
tolerates white spaces at the end of the chunk headers now (suggested by John Maindonald, #606) -
for R HTML documents, only the
highlight
component inopts_knit$get('header')
was used in previous versions; now all components exceptframed
andtikz
are used; this makes it possible to further customize the HTML header (thanks, Wahlen Neuwirth and Erich Neuwirth) -
in previous versions, the global option
KNITR_WIDTH
in R was used to setoptions(width)
; now this option is set fromopts_knit$get('width')
, which has the same default value75
(#597)
- if you are using Windows or Linux, you need to read the news about both versions 1.3 and 1.4, because the version 1.3 did not manage to survive on CRAN
-
the cache system is more granular now: instead of the binary option
cache = TRUE / FALSE
, we can specifycache = 0, 1, 2, 3
(TRUE
indicates 3, andFALSE
indicates 0; for 1 and 2, see the documentation forcache
: https://yihui.name/knitr/options); this means we may change the chunk options involved only with output rendering (e.g. fromecho = TRUE
toFALSE
, or setfig.cap = 'a new caption'
) without breaking the cache (thanks, Jeroen Ooms, Clark Kogan, and Roman Lustrik, #396, #536) -
added two new vignette engines called
docco_linear
anddocco_classic
using the Docco styles (http://jashkenas.github.io/docco/); seebrowseVignettes(package = 'knitr')
for examples -
added a function
rocco()
to compile R Markdown documents to HTML using the classic Docco style, i.e. a two-column layout, with text on the left and code on the right (thanks, Weicheng Zhu, #577) -
added an argument
comment
inspin()
to specify comment lines that will be ignored byspin()
; by default, the block comment/* comment */
is recognized; thanks, Bryan Hanson http://stackoverflow.com/q/17664401/559676 -
it is possible to set package options prior to loading the knitr package now: for a package option
foo
, we can setoptions(knitr.foo = value)
so that knitr willopts_knit$set(foo = value)
when callingknit()
; see?opts_knit
for details (thanks, Zhiguang Zhao) -
added a new argument
ext
to thepandoc()
function so that users can manually specify the output filename extensions (thanks, Baptiste, http://stackoverflow.com/q/17710249/559676) -
for LaTeX and HTML output, syntax highlighting can be done for languages besides R (e.g. Python, Perl, ...); this is achieved by
highr::hi_andre()
, so Andre Simon's Highlight must be installed, otherwise knitr will fall back to verbatim output for source code; see https://github.com/yihui/knitr-examples/blob/master/098-highlight-python.Rnw for an example (#495)
-
knitr formally depends on the highr package now (for syntax highlighting of LaTeX and HTML)
-
the package option
stop_on_error
has been deprecated; now it is much easier to specify whether you want to stop on errors or not by using the existing chunk optionerror
; if you want to stop, useerror=FALSE
; see the documentation for details: https://yihui.name/knitr/options -
the meanings of the chunk options
warning
andmessage
when they take the valueFALSE
have also changed:FALSE
means the warnings/messages will be printed in the R console and not recorded; this makes it easier to know when/where the warnings/messages were produced duringknit()
-
syntax highlighting and adding prompts are done in the
source
hook now; in previous versions, they were done inknitr:::wrap.source
; now thesource
hook receives the pure source code instead of syntax highlighted code
-
for the chunk options set in package option
opts_knit$get('eval.after')
, they will not be evaluated after a chunk ifeval=FALSE
for that chunk (#570, thanks, @knokknok) -
for document formats that produce HTML output, the default graphical device is changed to
png
only if it ispdf
; if the device has been changed to values other thanpdf
, knitr will no longer modify it internally; when thepng
device is not available, thesvg
device will be used instead -
removed the global option
KNITR_PROGRESS
, which was introduced to suppress the progress bar, but now we have gotknit(..., quiet = TRUE)
, so this option is redundant
- in LaTeX output, the double quotes
"
in the messages, errors, and warnings are replaced by"{}
because they might cause trouble to babel: http://stackoverflow.com/q/18125539/559676 (thanks, Thierry)
-
added support for AsciiDoc; see example 089 at https://github.com/yihui/knitr-examples/blob/master/089-minimal.Rasciidoc (thanks, Richard Cotton)
-
added support for reStructuredText vignettes in packages; now
*.Rrst
documents are recognized as vignettes as well, and they will be compiled to PDF viarst2pdf
(#533) (thanks, Trevor L Davis) -
a new function
kable()
to produce simple tables; see the vignettedatatables
inbrowseVignettes(package = 'knitr')
for an application; also see a LaTeX example at https://github.com/yihui/knitr-examples/blob/master/091-knitr-table.Rnw -
the chunk options
fig.width
andfig.height
are vectorized according to thedev
option, e.g.fig.wdith = c(7, 10)
anddev = c('pdf', 'png')
(#538) (thanks, @baptiste) -
for
purl()
, code chunks with the optionpurl=FALSE
will not be included in the R script (#519, thanks, Sebastian) -
new
'hide'
value to thefig.show
option; the figures are created but not included in the output document (#532) (thanks, Simon) -
the
sas
engine uses the listings output now (#541) and was tweaked for better LaTeX display (#562) (thanks, Nick Salkowski) -
added a quick and dirty
c
engine (viaR CMD SHLIB
); see https://github.com/yihui/knitr-examples/blob/master/090-engine-c.Rmd for an example -
added a new engine
asy
for Asymptote, a vector graphics language (http://asymptote.sourceforge.net); see examples 093 at https://github.com/yihui/knitr-examples (thanks, Thibaut Lamadon, #559) -
added a new engine
cat
to write the content of a code chunk to a file; see the example 095 at https://github.com/yihui/knitr-examples (thanks, Stephen Eglen) -
added a new function
knit_exit()
to allowknit()
to exit early as if it had reached the end of the document (#524, thanks, Renaud) -
the chunk option
fig.align
also works for Markdown output now, e.g.,fig.align = 'center'
will center images in HTML via thestyle
attribute of the<img>
tag (#387) -
the argument
format
in thepandoc()
function was vectorized, e.g. we can callpandoc(input, format = c('html', 'latex'))
and the input file will be converted to HTML and LaTeX, respectively (#547, thanks, Jeroen Ooms) -
added an argument
options
toknit_child()
to set global chunk options for child documents; if a parent chunk calls a child document (via thechild
option), the chunk options of the parent chunk will be used as global options for the child document, e.g. for<<foo, child='bar.Rnw', fig.path='figure/foo-'>>=
, the figure path prefix will befigure/foo-
inbar.Rnw
; see http://stackoverflow.com/q/17514055/559676 for an application -
eclipse_theme()
works with font weight (bold) and font style (italic) now when parsing themes from http://eclipsecolorthemes.org -
added two package options
latex.options.graphicx
andlatex.options.color
to allow customization of LaTeX package options, e.g.opts_knit$set(latex.options.color = 'monochrome')
generates\usepackage[monochrome]{color}
in the LaTeX output (#546) -
added a new package option
unnamed.chunk.label
to set the chunk labels for unnamed chunks, e.g.opts_knit$set(unnamed.chunk.label = 'fig')
will generate chunk labelsfig-1
,fig-2
, ... (#555) (thanks, Noam Ross) -
when
knit()
is running, a global optionknitr.in.progress
will be set toTRUE
; this allows other package authors (e.g.rCharts
andgoogleVis
) to adjust certain package options according togetOption('knitr.in.progress')
(thanks, Ramnath V, #564)
-
fixed #502: using
layout()
andpar()
at the same time under R 3.0.0 may lead to a corrupt plot (thanks, Hong Xu http://tex.stackexchange.com/q/108335/9128) -
fixed a bug in
pandoc()
: for single-lettered Pandoc arguments, the values are passed to them after spaces instead of equal signs (reported at http://stackoverflow.com/q/16569010/559676) -
fixed #542: when a child document has a sub-child document and also uses
set_parent()
, the LaTeX header will be added to the wrong file (thanks, Johan Toloe) -
stitch_rmd()
was using a wrong R Markdown template -
fixed #537: misleading error message when the graphical device does not exist (thanks, Scott Kostyshak)
-
fixed a bug in
hook_rgl()
reported at http://cos.name/cn/topic/110742 (incorrect LaTeX code whenfig.align='center'
andfig.show='hold'
) -
fixed #565: added the
envir
argument tospin()
so that the code is evaluated in the correct environment by default (thanks, @GillesSanMartin)
-
purl()
will write the chunk headers in# ---- label, opts ----
instead of# @knitr label, opts
, i.e.@knitr
was changed to four dashes----
; similarly,read_chunk()
will use the pattern# ---- label ----
to read external code (the old syntax# @knitr
is still preserved for compatibility); the main reason for this change is that RStudio uses four dashes in R comments as section headings, so that it is possible to fold sections of R -
syntax highlighting is done by the highr package if it has been installed, otherwise, the old regular-expression-based syntax highlighting will still be used; the highr package does much better syntax highlighting than the regexp-based approach (#327)
-
the commands for syntax highlighting were changed for compatibility with Andre Simon's Highlight package; this will affect LaTeX and HTML users, e.g.
\hlnumber
was renamed to\hlnum
; cached LaTeX and HTML will have to be rebuilt for the new syntax highlighting commands to work (#470) -
the argument
eval
was removed inknit_child()
; if we do not want to evaluate a child document, we can seteval=FALSE
in its parent chunk -
the script
inst/bin/knit
gains an option-o
to specify the output filenames forknit()
(#525, thanks, Aaron Wolen) -
the default video format for animations is OGG (it is open and free) instead of MP4 (non-free) now; this means Internet Explorer under Windows may not work with the animations (consider Firefox, Chrome and other modern web browsers)
-
warnings and messages in adjacent output chunks are merged, respectively (#534)
-
when the package option
verbose = TRUE
, the time stamp will be printed after each chunk usingtimestamp()
, but this will mess up with the R command history, so now knitr usescat()
to write the time stamp (#545) (thanks, @knokknok) -
the argument
base
inread_rforge()
was removed and hard-coded inside the function instead -
for Markdown output, the figure filenames no longer allow special characters like spaces, and special characters will be automatically replaced by
_
; this change will avoid problems when publishing to RPubs from RStudio: if figure paths contain special characters, the figures will not be uploaded (thanks, Sangsoon Woo)
- the package vignettes uses
\VignetteEngine{knitr::knitr}
instead of\VignetteEngine{knitr}
so that the next version of R can compile the vignettes out of the box (viaR CMD Sweave
) and no longer need to build the whole package in order to build the vignettes
-
the package vignettes were moved to the
vignettes
directory frominst/doc
since the former will be preferred by the future versions of R -
the testing is done via the testit package now (https://cran.r-project.org/package=testit)
- knitr becomes an affiliated project of FOAS (Foundation for Open Access Statistics): http://www.foastat.org/projects.html
-
added a Pandoc wrapper function
pandoc()
to convert Markdown documents to other formats that Pandoc support such as LaTeX/PDF, OpenDocument, HTML5 slides and unfortunately also Word (#206) -
in the past, the chunk hooks were ignored when the chunk option
engine != 'R'
(i.e. code in the chunk is not R); now they are executed regardless of the language of the code chunk (#483) (thanks, @cdrv) -
multiple WebGL objects from the rgl package can be generated in the same web page now; each object is uniquely identified by the corresponding chunk label; see https://dl.dropbox.com/u/15335397/misc/webgl-rmd.html for an example (#494) (thanks, Carson Sievert)
-
if multiple graphical devices are used (the chunk option
dev
is a vector of length greater than 1), the chunk optiondev.args
can be a named list of lists of device arguments, with each element a list of arguments to be passed to the single device; see https://yihui.name/knitr/options -
as announced in the last version, R 3.0.0 will support non-Sweave vignettes; now it is also possible to compile R HTML vignettes via knitr since
*.Rhtml
files are also registered by knitr as vignette files -
a new chunk option
cache.vars
to manually specify which variables to save in the cache database; by default all newly created and modified variables are identified and saved, but in some cases, knitr may not be able to identify the modified variables, e.g.DT[, foo:=value]
in data.table (we can setcache.vars='DT'
to force knitr to save a copy ofDT
) -
added a new engine
Rscript
to run the R code in a new R session; see http://stackoverflow.com/q/15271406/559676 for an example -
the executable script
inst/bin/knit
can accept multiple input files now (e.g.knit foo.Rnw bar.Rmd zzz.Rhtml
) -
knit()
andknit2html()
gained aquiet
argument to suppress messages and the progress bar (thanks, Vince Buffalo) -
added the
text
argument tospin()
andstitch()
respectively as an alternative way to provide the input likeknit()
(#509) (thanks, Craig Watson) -
a new function
wrap_rmd()
to wrap long lines in Rmd files without affecting the code blocks (if there are any); this makes it easier for version control purposes -
rst2pdf()
will pass a default output filename torst2pdf
(if the input isfoo.rst
, the output will befoo.pdf
) -
knit2wp()
gained a new argumentpublish = TRUE
(thanks, Eric Nantz) (#512)
-
fixed the problem reported in http://stackoverflow.com/q/12448507/559676 now \usepackage{upquote} should appear after \usepackage{fontenc}, so single quotes in verbatim environments will no longer cause problems
-
fixed #487:
stitch_rhtml()
andstitch_rmd()
should not use the chunk optionout.width = '.6\\linewidth'
(thanks, Tal Galili) -
when the chunk option
engine
is notR
, the code is also executed under the directoryopts_knit$get('root.dir')
(if specified); thanks, Winawer http://stackoverflow.com/q/15512545/559676 -
:
is permitted infig.path
now (#513) (thanks, Sebastian) -
fixed an encoding problem (
CP950
) for Hong Kong Windows users reported at http://bit.ly/16RQL5E
-
all child documents are inserted into the parent document as character strings of the (compiled) content, instead of being saved into files (e.g.
\input{foo-child.tex}
); no matter how many child documents there are, only one main output file will be generated; the package optionchild.command
was removed accordingly since it is no longer used -
no longer generates concordance data for child documents; the past attempt did not really work well and the implementation was complicated, so now we only support concordance for the main document; the consequence of this change is the synchronization between PDF and Rnw for child documents no longer works at the line level (clicking in PDF will still bring the focus back to the child chunk)
-
in previous versions, cached chunks were evaluated in separate (empty) environments in order to capture the newly created variables, but this brings confusion when we use functions depending on the current environment such as
ls()
(which will returncharacter(0)
); now all chunks, cached or not, are evaluated in the same environmentknit_global()
(finally fixed #456) -
knit2pdf()
andknit2html()
return the output filename when the input is a file (in previous versions,NULL
was returned in this case) -
the package option
stop_on_error
is set to2
now when building package vignettes, which means R will stop on errors in vignettes; this makes it easier to find out possible problems in vignettes duringR CMD build
-
the document hook
hook_rjournal()
was removed; it was too hackish (see https://yihui.name/en/2013/02/contribute-to-the-r-journal-with-lyx-knitr/ for how to write an article for The R Journal in a less hackish way)
- the progress bar symbol was changed from
>
to.
so it looks less intrusive (#395) (thanks, Michael Friendly)
-
the knitr book is forthcoming: http://www.crcpress.com/product/isbn/9781482203530 run
citation('knitr')
ortoBibtex(citation('knitr'))
in R to obtain the citation info -
open
help(package = 'knitr', help_type = 'html')
to see the vignette examples (Rnw, R Markdown and R HTML)
-
(experimental) R 3.0.0 will support non-Sweave vignettes, e.g. Rnw documents can be compiled by knitr instead of Sweave; in addition, R Markdown vignettes have also become first-class citizens as R package vignettes; see https://yihui.name/knitr/demo/vignette/ for details
-
a new engine for CoffeeScript (i.e. the chunk option
engine='coffee'
); see https://github.com/yihui/knitr-examples/blob/master/080-engine-coffeescript.Rmd for an example (thanks, Nacho Caballero) -
when the chunk option
eval=FALSE
,purl()
will comment out the code when extracting code chunks (thanks, Randall Pruim) -
the global option
KNITR_PROGRESS
can be used to set the package optionprogress
inopts_knit
, e.g. afteroptions(KNITR_PROGRESS = FALSE)
, this option will be set toFALSE
when the package is loaded (#395) -
the global option
KNITR_WIDTH
can be use to set the R optionwidth
before knitr is called; in the past this option was hard-coded to75
, and now it is set asoptions(width = getOption('KNITR_WIDTH', 75L))
-
a new function
knit2wp()
which compiles R Markdown documents and publishes the results to WordPress; see https://yihui.name/knitr/demo/wordpress/ for details -
a new hook
hook_webgl()
which writes the WebGL code of an rgl scene into the output usingrgl::writeWebGL()
so we can reproduce a 3D plot in the browser (thanks, Stephane Laurent http://stackoverflow.com/q/14879210/559676)
-
fixed #465: when
eval=FALSE
andecho
is numeric, the code was incorrectly filtered by the indices inecho
(thanks, @ateucher) -
>
was not allowed in HTML inline code expressions (http://stackoverflow.com/q/14360296/559676); now the regular expression works correctly to look for-->
instead of>
-
set_parent()
should not printNULL
in the child document: http://stackoverflow.com/q/14487718/559676 (thanks, Thomas Holz) -
child documents now inherit the encoding parameter from their parent document, i.e. the
encoding
value inknit(..., encoding = ?)
is applied toknit_child()
; note this assumes the parent document and the child documents use the same encoding (thanks, Henrik Nyhus)
-
empty inline expressions are no longer recognized, e.g.
\Sexpr{}
will not be parsed; this allows one to write such markers in tutorials (e.g.<!--rinline -->
and`r `
); internallyall_patterns$foo$inline.code
was changed -
the function
build_dep()
was removed (the warning has been there for a long time); please usedep_auto()
instead -
the package option
filter.chunk.end
was removed; this means in Rnw documents, a single line@
has the meaning of terminating a chunk only if there is a chunk header<<>>=
before it; otherwise it does not have any special meanings -
the function
run_chunk()
was removed; it is redundant because we already have the chunk optionref.label
as well as in-chunk reference<<label>>
-
the function
imgur_upload()
uses Imgur API version 3 now; if you are using the key obtained from version 2, you need to register for your own client id: http://api.imgur.com (#439) -
allow users to pass a custom environment to
Rcpp::sourceCpp()
in theRcpp
engine; fixes http://stackoverflow.com/q/14882486/559676 -
slight improvement of encoding support in
knit()
-
a new function
knit_expand()
which is similar to brew and mustache, e.g. it expandspi is {{pi}}
topi is 3.14
; it can also be used for building child documents (see https://github.com/yihui/knitr-examples/blob/master/075-knit-expand.Rnw for example) (#397) (thanks, Frank Harrell) -
knit()
gained a new argumentencoding
to specify the encoding of the input file (multilingual support is complete now), e.g.knit(..., encoding = 'GBK')
for Simplified Chinese -
a new function
Sweave2knitr()
to convert Sweave documents to knitr; several automatic translations can be done, e.g.results=tex
toresults='asis'
,width=5
tofig.width=5
,echo=true
toecho=TRUE
,keep.source=TRUE
totidy=FALSE
,eps=TRUE
todev='postscript'
,\SweaveOpts{...}
toopts_chunk$set(...)
and so on; see the documentation in the package for details (#451) -
if the Sweave syntax is detected in an Rnw document, a message box (tcltk) will pop up as a reminder on how to fix it
-
inline R code also respects the option
opts_knti$get('stop_on_error')
now, e.g. if we set this option to2L
, R will completely stop when error occurs in inline R code -
a new function
all_labels()
to get all chunk labels in a document; see one application at https://github.com/yihui/knitr-examples/blob/master/073-code-appendix.Rnw -
chunk hooks will be run (if exist) even if the code chunk is empty
-
added two wrapper functions
stitch_rhtml()
andstitch_rmd()
which use the R HTML and R Markdown templates respectively when callingstitch()
-
the chunk label is used as the id of the div element in R HTML output, e.g.
<div id='chunk-label'>...</div>
-
(IMPORTANT) the internal compatibility with Sweave has been dropped as scheduled in the last version, and the knitr parser was greatly simplified accordingly; Sweave users can call the function
Sweave2knitr()
to convert old Rnw files to knitr files before runningknit()
-
accordingly, the pattern elements
global.options
andinline.doc
were removed fromknit_patterns
(\SweaveOpts{}
and\SweaveInput{}
will no longer be supported; please callSweave2knitr()
to convert incompatible Sweave documents) -
chunk labels can be arbitrary characters now; in the past they had to be valid R symbols, e.g.
2a
was an invalid label; this restriction has been removed, because chunk labels will be automatically quoted when necessary (<<2a>>=
will become<<'2a'>>=
, but<<'3-function'>>=
will remain untouched) -
if the chunk option
include=FALSE
, the evaluation will stop if errors occur (i.e.stop_on_error=2L
for evaluate) because otherwise, it will be very difficult for authors to notice errors in chunks which haveinclude=FALSE
(#453) (thanks, Joshua Pritikin) -
the function
knit_env()
is no longer available (it is not exported any more), andknit_global()
has been exported now
- for inline R code, the value is returned only if the R code prints a visible value, e.g.
\Sexpr{x <- 1}
will be empty, and\Sexpr{pi}
will return the value ofpi
-
fixed #432: no longer uses
\\\\
in LaTeX output; only a single line break is converted to\\
(thanks, Kevin Wright) -
render_html()
guarantees that the R source code is highlighted when the chunk optionhighlight = TRUE
(#447) (thanks, Ramnath Vaidyanathan) -
dep_auto()
was unable to find the cache files if the input document is not under the current working directory (thanks, Hui Yao)
- because Github has deprecated downloads, all downloads were moved to Bitbucket, and the links in the package website, as well as all examples, have been updated (#438)
-
added a demo named
notebook
which is an R notebook based on the shiny package (https://github.com/rstudio/shiny); usedemo('notebook', package = 'knitr')
to see it, or visit http://glimmer.rstudio.com/yihui/knitr -
for numeric inline output in LaTeX, the
I()
trick is no longer needed, e.g.$x=\Sexpr{1.2e10}$
is safe for LaTeX now due to\ensuremath{}
(#137) (thanks, Randall Pruim) -
the chunk option
eval
can take numeric values now, specifying which expressions to evaluate in a chunk (#383) (thanks, Jared Lander) -
a new package option
stop_on_error
which specifies the behavior of errors in code chunks; this option is passed to the evaluate package, e.g.opts_knit$set(stop_on_error = 2L)
will make knitr completely stop on errors (the default value is0L
which means to move on even if errors occurred); this makes it possible to see the call stacks viatraceback()
in an interactive R session when an error occurs (#344) (thanks, Hadley Wickham and Dzidorius Martinaitis) -
added support to the Rcpp package through the chunk option
engine='Rcpp'
so that we can write C++ source code in the document; see https://github.com/yihui/knitr-examples/blob/master/029-engine-Rcpp.Rmd for an example (#415) (thanks, JJ Allaire) -
knitr throws a warning when a cached chunk depends on an uncached chunk because this kind of dependency will be ignored (#431) (thanks, @ghostwheel)
-
a list of arguments can be passed to
formatR::tidy.source()
as the chunk optiontidy.opts
now, e.g.tidy.opts=list(width.cutoff=60, keep.blank.line=FALSE)
(#429) -
some chunk options are recycled for plots such as
fig.env
,out.width
andout.extra
, etc; this means if there are multiple plots per chunk, we can specify different output options for them individually (e.g.out.width=c('2in', '.4\\linewidth')
for two plots); see https://github.com/yihui/knitr-examples/blob/master/067-graphics-options.Rnw for an example (motivated by #430) (thanks, @autumnlin) -
added a new chunk option
fig.subcap
for captions of subfigures in LaTeX; when there are multiple plots in a chunk, and neitherfig.subcap
norfig.cap
is NULL,\subfloat{}
will be used for individual plots (you need to add\usepackage{subfig}
in the preamble); also see https://github.com/yihui/knitr-examples/blob/master/067-graphics-options.Rnw for an example (#388) (thanks, @skipperhoyer) -
stitch()
accepts labelled R scripts now; if an R script contains chunk headers of the form## @knitr label, options
, they will be used in the template (#411) (thanks, @jamiefolson) -
the function
read_chunk()
gained a few new arguments so that we can reference external code chunks in another way, which was an idea from the SweaveListingUtils package (thanks, Peter Ruckdeschel) -
a new function
read_demo()
based onread_chunk()
to read demo scripts in R packages -
a new convenience function
read_rforge()
to read code from R-Forge repositories; combined withread_chunk()
, it can insert R code from R-Forge into knitr dynamically; see https://github.com/yihui/knitr-examples/blob/master/046-read-rforge.Rmd for an example (thanks, Peter Ruckdeschel) -
chunk options are also written after
## @knitr
along with chunk labels when tangling R scripts viapurl()
-
purl()
gained a new argumentdocumentation
to also write documentation lines into the R script (#391 and #401) (thanks, Noam Ross and Fernando Mayer) -
knit_rd()
generates a navigation frame on the left and builds links now; this is like the CHM help in old days (thanks, Michael Friendly) -
a new function
knit_rd_all()
to build static HTML help pages for all the packages installed -
we can also use
## @knitr
to write chunk options forspin()
now (#+
and#-
still work) -
added new language support for Perl and Z Shell (
zsh
); see an example at https://github.com/yihui/knitr-examples/blob/master/028-engine-perl.Rmd (#406) (thanks, Jim Hester) -
render_jekyll()
gained an argumenthighlight
to specify which highlighting engine to use (Pygments or Prettify.js) (thanks, Yanping Chen) -
two new chunk options for language engines:
engine.path
andengine.opts
; the former can be used to specify the path of the program (e.g.<<engine='ruby', engine.path='/usr/bin/ruby1.9.1'>>=
); the latter can be used to pass additional arguments to the engine program -
added new engines for GraphViz (
engine='dot'
) and TikZ (engine='tikz'
); see https://github.com/yihui/knitr-examples/blob/master/057-engine-dot.Rmd and https://github.com/yihui/knitr-examples/blob/master/058-engine-tikz.Rmd for examples (#419) (thanks, Michel Kuhlmann) -
added a preliminary engine for SAS which is basically a call like
system('sas chunk-code.sas')
(#354) -
a new
document
hook to post-process the LaTeX output document to move code chunks out of figure/table environments so that code chunks will not float with the environments; see?hook_movecode
for details -
chunk hooks are called in the reverse order after a chunk (and natural order before a chunk); this allows one to, e.g. write an opening environment before a chunk and close it properly after a chunk
-
all language engines also respect the
comment
option when writing output just like R code chunks (by default the output is commented out by##
) -
added a new function
set_alias()
as a wrapper toopts_knit$set(aliases = ...)
, e.g.set_alias(w = 'fig.width')
setsw
as an alias for the chunk optionfig.width
-
global options are strongly recommended to be set via real R code
opts_chunk$set(opt = value)
in a code chunk instead of the old syntax in text chunks like\SweaveOpts{opt = value}
, or<!--roptions opt=value-->
, etc, which will be deprecated in the next version; this will make it cleaner and safer to parse the source documents, e.g. we can write arbitrarily complicated expressions likeopts_chunk$set(fig.width = if (foo == 'beamer') { 5 } else { 7 })
which is impossible in the old syntax; if you still use the old syntax like\SweaveOpts{}
, you will see a warning with a pause of 10 seconds -
based on the same reason, it is recommended to use the chunk option
child
to input child documents; old syntax like\SweaveInput{}
will be deprecated -
for markdown output, results from inline R code will no longer be put in a pair of backticks (#379)
-
the package option
opts_knit$get('cache.extra')
was removed because this option should really be a chunk option instead; see https://yihui.name/knitr/demo/cache/ for the updated documentation (#404 and #405) (thanks, Jim Hester) -
the chunk option
highlight.opts
was deprecated and renamed toengine.opts
; this affects users who use Andre Simon's highlight through thehighlight
engine in knitr -
the chunk option
file
for Awk was deprecated; we can also useengine.opts
to specify the file for Awk; see https://github.com/yihui/knitr-examples/blob/master/024-engine-awk.Rmd for example -
the pattern
knit_pattern$get('ref.label')
was deprecated since it is unlikely to be customized; a fixed pattern'^#+\\s*@knitr(.*)$'
will be used instead
-
when
opts_knit$get('verbose')
isTRUE
, atimestamp()
will be printed before each code chunk is evaluated (#377) (thanks, Carl Boettiger) -
stitch()
will no longer copy the template over to the current working directory (thanks, Michael Friendly) -
stitch()
will no longer open the PDF/HTML output automatically (#411) (thanks, Michel Kuhlmann) -
the script
inst/bin/knit
can also convert R Markdown documents to HTML now; the argument--pdf
was removed and a new argument--no-convert
was added -
dots in figure filenames will not be replaced with
_
when the output is not LaTeX (thanks, Stewart Macarthur)
-
fixed #410: when the inline R code returns
NA_real_
, the scientific notation of numbers will run into errors (thanks, Rafik) -
the syntax pattern for Rnw documents was not quite right:
all_patterns$rnw$chunk.end = '^\\s*@\\s*%*'
actually allows any characters after@
, but only LaTeX comments and white spaces are allowed; it has been fixed to^\\s*@\\s*(%+.*|)$
now
- an example of combining R, knitr and D3 to draw a contour plot: https://yihui.name/knitr/demo/javascript/
-
output from other languages (e.g. python, awk, ...) can also be cached like R output when
cache=TRUE
; see 023-engine-python.Rmd for an example -
added support for bash/shell scripts; use the chunk option
engine='bash'
orengine='sh'
to write shell scripts in code chunks (#361) -
a new function
knit_rd()
to knit package documentation (run examples code and insert output in the HTML documentation) (#227) (thanks, Taiyun Wei) -
added LuaTeX support for tikz graphics with the tikzDevice package (set
options(tikzDefaultEngine = 'luatex')
); this feature requires tikzDevice version > 0.6.2 (#358) (thanks, Alastair Andrew) -
a new chunk option
fig.env
to set which environment to use for figures in LaTeX, e.g. we can setfig.env='marginfigure'
to use\begin{marginfigure}
(#364) (thanks, Bryan Hanson) -
added a new package option
global.device
(defaultFALSE
) which specifies whether to use a global graphics device to capture plots; ifTRUE
, it is possible to writeplot(1:10)
in a previous chunk andabline(0, 1)
in a latter chunk because all code chunks share the same device, however, this may also bring unexpected consequences (in particular, usingpar()
can bring redundant plots)
-
dots in figure paths are more safely replaced with
_
now, e.g.fig.path='../figure'
will no longer be replaced by__/figure
(#346) (thanks, @ralfer) -
the
c()
syntax for the chunk optiondependson
did not actually work, e.g.dependson=c('foo', 'bar')
(#350) (thanks, Cassio Pereira) -
fixed a bug when
eval=FALSE
andprompt=TRUE
(the continuation character was used in some places where there should be the prompt character) (thanks, Derek Ogle) -
persp()
plots were not recognized in the last version (thanks, Jeffrey Racine)
-
leading spaces are allowed in chunk headers now, e.g. in the past
<<>>=
must appear in the beginning of a line, but now we can indent the chunk header by a number of white spaces; this amount of spaces will be stripped off the chunk if the whole chunk is indented (#236) (thanks, @jamiefolson and Vitalie Spinu) -
markdown output will be indented if the original code chunk is indented; this allows chunk output to be nested within its parent environment, e.g. inside an ordered list (see 001-minimal.Rmd for example)
-
when the global chunk option
eval=FALSE
, inline R code will not be evaluated, and??
is returned for inline R expressions (#367)
-
if
getOption('OutDec')
is not.
, inline numeric output will be put inside\text{}
in LaTeX to avoid situations like #348 (the normal math mode may add a space after the comma in3,1415
) -
if the chunk option
external==FALSE
(default isTRUE
), knitr will no longer automatically add\usepackage{tikz}
to the LaTeX preamble; you need to add it manually (but it is recommended to useexternal=TRUE
withcache=TRUE
for the sake of speed, because compilation of tikz graphics may be slow) -
*.brew
generates*.txt
by default (instead of*-out.brew
) -
knit(text = ...)
will no longer write output in the console (the output is only returned as a character string)
- added a simple reference card: http://cran.rstudio.com/web/packages/knitr/vignettes/knitr-refcard.pdf
-
added a new chunk option
out.extra
to write extra graphics output options, e.g.<<out.extra='angle=90'>>=
to rotate the figure by 90 degrees; see https://yihui.name/knitr/options (#301) (thanks, @knokknok) -
when
opts_knit$get('verbose')
is TRUE, logs (messages, warnings and errors) along with the corresponding R code will be printed afterknit()
is done; this might help users figure out possible problems in R code quickly (#276) -
.Random.seed
is cached again for the sake of reproducibility; see https://yihui.name/knitr/demo/cache/ for how to maintain reproducibility when the computation involves with random number generation (#274) (thanks, Renaud) -
the package option
opts_knit$get('cache.extra')
can be an unevaluated R expression now, e.g.opts_knit$set(cache.extra = quote(.Random.seed))
; see the cache page above for a concrete example -
added a new package option
'root.dir'
(defaultNULL
) which can be used to set the root directory to evaluate code chunks in a document; by default, the root directory is the directory of the input document, and this option enables users to set other directories as the working directory for code chunks (#277) (thanks, Ken Williams) -
spin()
will add\documentclass{article}
for Rnw output if no document class is specified in the R script so that the LaTeX output will be a complete document (#295) (thanks, Christiaan Klijn) -
added Ruby support in the
engine
option; see the example https://github.com/yihui/knitr/blob/master/inst/examples/knitr-lang.Rmd (#294) (thanks, Ramnath Vaidyanathan) -
also added Haskell support in the option
engine='haskell'
through callingghc
(#336) (thanks, Michel Kuhlmann) -
added support to Andre Simon's
highlight
through the optionengine='highlight'
; see https://gist.github.com/3114112 for an example of highlighting Matlab code in LaTeX (thanks, Dirk Eddelbuettel and Renaud Gaujoux) -
the output hooks for LaTeX, HTML, Markdown and reST will respect the
engine
option now, so these hooks can be readily used for output when the language is not R, e.g.render_markdown(strict = TRUE)
also works for Python output (#251) (thanks, Chris Fonnesbeck) -
the chunk options
eval
,echo
andresults
are also respected when the language is not R, e.g. for a Python code chunk witheval=FALSE
, the code will not be evaluated, or for a Ruby chunk withresults='hide'
, the output will be hidden (#293) (thanks, Ramnath Vaidyanathan) -
chunk options
out.width
,out.height
andout.extra
also work for plots in HTML and Markdown output now, e.g.out.width='200px'
orout.extra='style="display:block;"'
(#297) (thanks, Taiyun Wei and Alan Severini) -
the hook function to create animations in HTML output is exported now as
hook_ffmpeg_html()
-
added a package option
opts_knit$get('animation.fun')
which defaults tohook_ffmpeg_html
; this option is used to create animations in HTML output so that we do not have to use FFmpeg -
added two functions
hook_r2swf()
andhook_scianimator()
which can be set as the package optionopts_knit$get('animation.fun')
and create animations via the R2SWF package or the SciAnimator library (seeanimation::saveHTML
) (thanks, Taiyun Wei) -
a new function
image_uri()
to create data URIs for image files; we can setopts_knit$set(upload.fun = image_uri)
so that images are embedded in the HTML output as data URIs (hence the HTML page does not depend on external images) (#298, #324) (thanks, Wush Wu) -
added a new object
opts_template
which can be used to set a group of chunk options and they can be referenced later with the new chunk optionopts.label
; see?opts_template
for examples; this makes it easy to reuse groups of frequently used chunk options (#316, #320) (thanks, Cassio Pereira) -
a new function
dep_prev()
to build chunk cache dependencies so that all later chunks will depend on previous chunks; if any of a previous chunk is updated, the cache of all chunks after it will be updated as well (#285) (thanks, @muelleki) -
a new chunk hook function
hook_optipng()
to optimize PNG images usingoptipng
(#272) (thanks, Winston Chang) -
added a new output hook named
document
inknit_hooks
(seeknit_hooks$get('document')
); this hook function is used to process the output of the whole document; it can be useful when we want to post-process the whole output before writing it to the output file -
a new function
rst2pdf()
which uses the programrst2pdf
to convert reST documents to PDF; it is also supported byknit2pdf()
whencompiler='rst2pdf'
(#300) (thanks, Alex Zvoleff)
-
fixed #286: messages (including warnings and errors) are guaranteed to be ended by
\n
, so even when chunk optioncomment=NA
, messages will also be rendered correctly (thanks, Carl Boettiger) -
fixed #273: when knitting a file under another directory with cache turned on (e.g.
knit('foo/bar.Rnw')
),lazyLoad()
is unable to load the cache files under a relative path because the working directory has been changed to the directory of the input file during the evaluation -
fixed #292: layout() may cause the capture of unwanted plots (thanks, Austen Wallace Head)
-
fixed #302: when there are multiple instances of
\documentclass
in the source document, knitr will be unable to insert the LaTeX preamble -
fixed #308: if
options('OutDec')
was set to a character other than.
, the LaTeX code can be malformed (#308) (thanks, Cassio Pereira) -
opts_chunk$set()
in a child document was only working in that child document, but was expected to change chunk options globally; now it works everywhere, and will affect all chunks after this setting, no matter whereopts_chunk$set()
is (thanks, Guy Lebanon) (http://bit.ly/MexHXd) -
fixed #332: calling
purl()
inside a source document whenknit()
the same document could cause clashes; now it is safe to putpurl()
inside a source document andknit()
it -
fixed #342: when
eval=FALSE
, line breaks in the source code were missing
-
if the chunk label contains non-alphanumeric characters (except
-
and_
), these characters will be replaced by_
in the figure filenames (if there are any) and a warning will be issued; this is to guarantee the figure filenames are valid to LaTeX (#321) (thanks, (Roman Lustrik) -
the highlight package is not enabled by default; use
opts_knit$set(use.highlight = TRUE)
to enable it -
the default LaTeX output will put messages, warnings and errors in special LaTeX environments: errors are red, warnings are magenta, and messages are italic; in previous versions, they were in the
verbatim
environment (#264) (thanks, @muelleki) -
unnamed chunks are named sequentially in a single call of
knit()
according to the order of their appearance no matter where they are, e.g. if there are two unnamed chunks in two child documents respectively, they will be namedunnamed-chunk-1
andunnamed-chunk-2
; in previous versions, both will be named asunnamed-chunk-1
which can cause clashes of cache and figure files -
the function
build_dep()
was renamed todep_auto()
which better reflects what this function really does; it is still available in this package but may be removed in future versions -
the package tikzDevice was removed from the
Suggests
field, but this will not affect users who have already installed tikzDevice; for those who have not, this package has been archived on CRAN (hopefully only temporarily), so you have to install from the source
-
the LaTeX environment
kframe
was updated so that it can be used in other environments such ascenter
ortabular
(#283) (thanks, @muelleki) -
the OpenCPU demo is more robust to double quotes in the text (#271); see http://public.opencpu.org/userapps/opencpu/knitr/
-
for Sweave output, the results will not be put inside the Schunk environment when
results='asis'
-
stitch()
templates use more sensible figure paths by default: the path for figures is'figure/input-script-name'
now, i.e. it will be different for different input R scripts to avoid possible clashes -
stitch()
templates no longer use default title and author names; if the user did not set them in the R script (as meta comments# title:
and# author:
), there will not be titles or authors in the output -
knitr will no longer use scientific notations for integers in inline R code output; sci notation only applies to double-precision numbers (#296) (thanks, @knokknok)
-
options()
set in the main document will apply to its child documents (e.g.options('digits')
) (#306) (thanks, Cassio Pereira) -
the
...
argument inknit2html()
is passed tomarkdown::markdownToHTML()
instead ofknit()
; this allows us to pass more arguments to control the rendering of HTML output, e.g.knit2html(input, fragment.only = TRUE)
(#333) (thanks, @Bart6114)
- the example using other languages was updated to show how some chunk options (
eval
,echo
andresults
) also work for foreign languages: https://github.com/yihui/knitr/blob/master/inst/examples/knitr-lang.Rmd
- this is an urgent patch version for CRAN: the dependencies on highlight and parser were removed because these two packages were orphaned on CRAN; now knitr uses a naive syntax highlighter for LateX and HTML output if highlight is not available, which has a similar appearance with highlight; when the parser package is not available, users should be careful with the chunk option
tidy=TRUE
:replace.assign
may not work as expected; see the NEWS of formatR for details: https://github.com/yihui/formatR/blob/master/NEWS; you are welcome to improve the naive highlighter: https://github.com/yihui/knitr/tree/master/R/highlight.R
spin()
gained a new argumentreport
for Rnw/Rtex/Rmd documents to be compiled to PDF/HTML respectively (#287) (thanks, kohske takahashi)
-
stitch()
andspin()
should useparent.frame()
to evaluate code by default; in 0.6, the default parent frame for the innerknit()
was a wrong environment to use (thanks, Michael Nelson) -
use
unnamed-chunk-i
as the label when chunklabel == ''
(#280) (thanks, Josh Paulson) -
fixed #279 and #281, both of which are about concordance
-
'\\maxwidth'
does not apply to LaTeX/PDF animations, so the default value ofout.width
for animations in LaTeX is stillNULL
; you will have to setout.width
manually for a reasonable width (#282) (thanks, Ramnath Vaidyanathan)
- knitr and RStudio had an invited talk at useR! 2012; slides at https://yihui.name/slides/2012-knitr-RStudio.html (source at https://github.com/yihui/knitr-talks)
-
for LaTeX output, the chunk option
out.width
defaults to'\\maxwidth'
now; see https://yihui.name/knitr/demo/framed/ for its definition; this makes sure the figures do not overflow the page margins (#221) -
the chunk option
size
now defines the font size of the whole chunk instead of only some special characters in it, so that the old trick of redefining theknitrout
environment for different font sizes is no longer necessary; see updates in the beamer examples: https://yihui.name/knitr/demo/beamer/ (thanks, Baptiste Auguie) -
added a new chunk option
dev.args
which can be used to pass more arguments to the graphical device (#254) (thanks, knokknok) -
warnings, messages and errors will be wrapped according to
options('width')
; this will make long messages stay within the page margin when the width option is appropriately small (#259) (thanks, @muelleki) -
added a new function
spin()
to turn a specially formatted R script to a report; see https://yihui.name/knitr/demo/stitch/ (#223) (thanks, Rich FitzJohn) -
knit()
gained a new argumentenvir
to specify the environment in which to evaluate code chunks (by default in the parent frame); this will allow users to run code in a specified environment so that the global environment will not be cluttered by objects in chunks, which can hopefully make the documents more reproducible (#228) -
added a new component
inline.comment
inknit_patterns
to strip off tokens of inline R code from inline comments, e.g. a comment line like% x is \Sexpr{x}
will become% x is x
(#110); this will only happen to LaTeX documents because HTML does not have inline comments (it only has block comments<!-- -->
) -
concordance works for child documents as well now (try RStudio), although it is not very precise (#225); note when concordance is enabled, the results from child documents will be written into the parent output instead of individual tex files; also note you have to set
opts_knit$set(self.contained = FALSE)
for concordance to work better -
added an OpenCPU app so that we can run knitr in the cloud now; see
system.file('opencpu', 'apps', 'index.html', package = 'knitr')
or http://public.opencpu.org/apps/knitr (thanks, Jeroen Ooms) -
all messages, errors and warnings during evaluation are recorded in an internal object
knit_log
(useknitr:::knit_log$get()
to get all messages) and they are printed if the package optionverbose
isTRUE
(i.e.opts_knit$get('verbose')
) (#224) -
child documents are also supported in other document formats besides LaTeX, e.g. Markdown and HTML, etc; please use the chunk option
child
to specify the child documents; seesystem.file('examples', 'child', 'knitr-main.Rmd', package = 'knitr')
for an example in markdown (#268) (thanks, @martinaryee)
-
the templates for
stitch()
usedresults=hide
which should really beresults='hide'
(#219) (thanks, @r2d3) -
format numbers with the reST syntax instead of HTML (#218) (thanks, Jeffrey Arnold)
-
hook_pdfcrop()
should work better under Windows now (#209) (thanks @DCCKC and @r2d3) -
tikz compilation fails on Windows network drives
-
FFmpeg does not really work for HTML/Markdown output because the dot in figure filenames was omitted (thanks, Ming Kuo)
-
child documents can fail when they are in different subdirectories (thanks, Christoph J)
-
set_parent()
failed to work in the last version due to a bug when inserting the parent preamble into the child document (#240) -
better preserve plot sizes in interactive sessions (#258)
-
.Random.seed
is not cached any more because of weird problems due to lazy loading (#248 and #253); users should useset.seed()
to make sure reproducibility of random simulations; the chunk output is cached in a.RData
database instead of a lazy-load database to avoid problems in #253 -
the default graphics device is set to the null PDF device before evaluating code chunks, i.e.
pdf(file = NULL)
, so that neitherRplots.pdf
nor plot windows will be opened during knitting
-
knitr will show a message when a chunk is empty; this helps users who do not actually want a chunk to be empty realize the problem like #229; in the past, knitr just silently returns an empty string from such chunks
-
knitr will show a message when the cache is loaded and the option
opts_knit$get('verbose')
isTRUE
(#249) (thanks, Carl Boettiger) -
the filename extensions
Snw
andStex
are also supported (foo.Snw
/foo.Stex
producesfoo.tex
) -
the HTML output hooks are changed according to the suggestion of Barry Rowlingson (#250) and the default CSS is also slightly modified
-
knit()
will no longer try to remove the fileNA
generated bypdf(file = NULL)
before R 2.14.2 (which was a bug and fixed later); you should update R if you see this file
- added a minimal brew example under
system.file('examples', package = 'knitr')
-
white spaces are allowed before
<<>>
when using chunk references, and this approach of references is supported in tex and html documents as well -
added a new pattern list named
md
so that R code blocks can be written more naturally in extended markdown (e.g. GFM and pandoc): use```{r label, opts}
to begin a chunk and```
(three or more backticks) to begin normal text, and write inline R code in`r code.here`
; it is the default syntax for markdown input, or you can callpat_md()
beforeknit()
so knitr can make use of this pattern list to process the input document -
RStudio has added full support to knitr: we can knit HTML and Markdown documents easily now, and markdown output will be automatically converted to an HTML preview page just like TeX to PDF
-
if the pattern list is not set in advance, knitr will try to detect the syntax automatically by matching all built-in pattern lists against the input document, e.g. if the input contains
<<>>=
, the Rnw syntax will be used, and if```{r}
is detected, the markdown syntax will be used; this feature enables us to use different sets of syntax freely, e.g. we can use Sweave syntax in markdown files and knitr will be able to recognize it (#189) -
new filename extensions with a prefix
R
orr
are introduced:*.Rhtml
,*.Rhtm
,*.Rtex
,*.Rmd
and*.Rmarkdown
will be recognized as source documents like*.Rnw
, and the output filename will be automatically determined by removing theR
prefix, e.g.foo.Rmd
producesfoo.md
by default; the old clumsy naming conventionfoo_knit_.md
is still preserved but not recommended any more (#187) -
new function
knit2html()
to knit an Rmd file (R with markdown) and convert to HTML in one step using the markdown package -
new functions
pat_rst()
andrender_rst()
to support reStructuredText; use.. {r label, options}
and.. ..
to write R code chunks; see https://github.com/yihui/knitr/tree/master/inst/examples/knitr-minimal.Rrst (thanks, Jeffrey Arnold and Ramnath Vaidyanathan) -
new package option
self.contained
which decides whether to write style definitions (highlighting) in external files or put them in the output document; the highlighting definitions in LaTeX output is often too long, soopts_knit$set(self.contained = FALSE)
can help in this case (#176) (thanks, Ramnath Vaidyanathan) -
new package option
filter.chunk.end
which decides if thechunk.end
pattern really meanschunk.end
; see https://yihui.name/knitr/options (thanks, Joe Cheng) -
syntax highlighting themes are also available to HTML output now; the usage is the same as in LaTeX (#179) (thanks, Ramnath Vaidyanathan)
-
the chunk option
fig.cap
is also used in markdown output now -
the random seed
.Random.seed
is also cached for the sake of reproducibility in random simulations -
the function call
read_chunk()
will be evaluated when tangling R code viapurl()
(#175) (thanks, Carl Boettiger) -
the default LaTeX output will use the upquote package if it exists so that single quotes are straight in the output (thanks, Mathematical Coffee http://bit.ly/IKjluw)
-
the chunk option
engine
is back but it is used to run code from other languages instead of just ignoring the code in chunks which haveengine != 'R'
; currently this option is still in rough edges and only supports python and awk; other languages may be added in future versions, but users can also do it by themselves byknit_engines$set(language = function(options) {...})
; see an example atsystem.file('examples', 'knitr-lang.Rmd')
(#201) -
new function
write_bib()
to write Bibtex citations for R packages; see the main manual for a sample usage (#13) -
hook_pdfcrop()
also supports cropping other image formats like PNG or JPEG through ImageMagick (convert -trim
) (#203) (thanks, @r2d3)
-
knitr will completely stop when duplicated labels are found and the corresponding chunks are non-empty; in the previous version, only a warning is given and R code in later chunks will override previous chunks (#185) (thanks, Randall Pruim)
-
the default graphical device for HTML and markdown output is
png()
now to avoid the possible unexpected consequence that PDF plots are included in an HTML page which will not work normally in browsers -
markdown output will use the extended markdown hooks by default now:
render_markdown(strict = FALSE)
; in the past the default wasrender_jekyll()
; the major difference is that the code blocks are put in```r and ```
; if you want the strict markdown syntax, you can allrender_markdown(strict = TRUE)
which will indent code blocks by 4 spaces -
render_gfm()
has been removed because the name can be misleading; the main purpose of this function was to put code blocks in```
, and now we can replace it byrender_markdown(FALSE)
; other markdown flavors also support such fenced code blocks (e.g. pandoc) -- it is not limited to Github only -
the default value for the
fig.path
option is'figure/'
now so that plots will be put under this directory by default; the default was'./'
in the past which makes the current directory messy when there are many plots -
knitr will fully stop when an error is encountered in
knit()
; in the past, only a message was issued in this case in an interactive R session -
the package option
all.patterns
has been dropped; please use the objectsall_patterns
orknit_patterns
directly if you want to tweak the syntax
-
the compilation of tikz graphics can hang up when there are TeX errors in the tikz file; now we use
\nonstopmode
to avoid hiccup (#188) -
multiple devices per chunk was buggy (#181)
-
S4 objects will be printed by
show()
instead ofprint()
; this is a bug of the evaluate package, which has been fixed (please update it to be > 0.4.2)
-
it is recommended to use
opts_chunk$set()
to set global chunk options now instead of\SweaveOpts{}
; all documentation has been updated (#216) -
number of downloads (https://github.com/yihui/knitr/downloads) of knitr documentation before I removed and updated them on GitHub: c(main = ?, graphics = 275+)
-
Sweave concordance was finally implemented: when
opts_knit$get('concordance')
isTRUE
, knitr will write a file named'input-concordance.tex'
which contains the mapping between input Rnw and output tex line numbers; this feature is mainly for (but not limited to) RStudio to provide better error navigations: you can jump from the TeX error message to the Rnw source directly to know where the error comes from (the line number of the source of the error may not be accurate but should be in the ballpark) (#133) (thanks, JJ Allaire and Joe Cheng) -
if output hooks have been set before calling
knit()
, they will be respected, i.e. knitr will no longer override them by default hooks; you need to make sure all output hooks are set appropriately, e.g. you can start byrender_latex()
and change some individual hooks later (#165) (thanks, Andrew Redd) -
newly created objects in the global environment will also be cached if cache is turned on (
cache=TRUE
); in previous versions knitr is unaware of objects created inglobalenv()
, e.g.setGeneric()
creates S4 generic functions inglobalenv()
and knitr was unable to capture them (#138) (thanks, syoh) -
chunk options
dev
,fig.ext
anddpi
can be vectors now; this allows one to save a plot to multiple formats, e.g.<<foo, dev=c('pdf', 'png')>>=
creates two files for the same plot:foo.pdf
andfoo.png
(#168) (thanks, MYaseen208) -
an experimental feature for animations created by FFmpeg in HTML/markdown output when
fig.show='animate'
(#166) (thanks, gabysbrain) -
the chunk option
fig.cap
supports multiple figure captions in LaTeX now, e.g. if a chunk produces two plots, we can usefig.cap = c('first caption', 'second caption')
to assign two different captions to them respectively whenfig.show = 'asis'
(#155) (thanks, Jonathan Kennel) -
new package option
opts_knit$get('upload.fun')
which is a function that takes a plot file to upload to a certain host and returns the link to the image; by default it isimgur_upload()
, and you can use your own function to upload images to other hosts like Flickr (#159) (thanks, Carl Boettiger) -
all packages loaded in the current session are also cached, so as long as a package has been loaded previously, it will be available to all following chunks (#160)
-
new chunk option
autodep
and functionbuild_dep()
to build cache dependencies among cached chunks automatically by analyzing object names in all cached chunks; this is a loose alternative to thedependson
option (see main manual and?build_dep
for details) (#72) (thanks, Seth Falcon) -
input and output in
knit()
are no longer restricted to files; they can bestdin()
/stdout()
or other types of connections (#162; see yihui#162) (thanks, gabysbrain) -
as-is output (
results='asis'
) and plots are no longer put in the framed environments because of incompatibilities (#163) (thanks, DCCKC, Murray Logan and Jennym Hutchison)
-
for plots in LaTeX output, centering should be done with
{\centering }
instead of\centering{}
(#156) (thanks, Ramnath Vaidyanathan) -
the recorded plot is a more precise representation of the expected plot now because the recording device also takes the plot size into consideration (#157) (thanks, Christiaan Klijn and Frank Harrell)
-
format_sci()
now correctly formats 0; this function is used for inline R code to format numbers in scientific notation (#161) (thanks, Kihoro J. M.) -
fixed a bug for the case in which the chunk option only contains the label like
<<label=foobar>>=
; knitr 0.3 was unable to parse the label correctly (<<foobar>>=
is OK) (thanks, Muhammad Yaseen)
-
imgur_upload()
returns the link to the image directly, with the XML list as its attribute (in v0.3 the list was returned) -
more verbose messages in case of chunk errors: both line numbers of the source and chunk info will be printed
-
website updated as usual: https://yihui.name/knitr
-
added an example for the subfloat environment: https://github.com/yihui/knitr/releases/download/doc/knitr-subfloats.pdf
-
most manuals (main or graphics manuals) have been updated
- number of downloads (https://github.com/yihui/knitr/downloads) of knitr documentation before I removed and updated them on GitHub: c(main = 400, graphics = 177)
-
a fundamental and important new feature for writing chunk options: they can be written as valid R code now, just like we write function arguments (e.g.
echo=c(1, 3, 5)
,fig.cap="my figure caption"
); all options will be parsed and evaluated as R code by default; see https://yihui.name/knitr/options for details (#142) (thanks, Baptiste Auguie) -
chunk references using
<<label>>
is supported now (#86); thanks to Kevin R. Coombe and Terry Therneau for the discussion -
new function
run_chunk()
to run the code in a specified chunk, which is an alternative to the chunk reference in Sweave; see https://yihui.name/knitr/demo/reference/ -
a executable script
knit
undersystem.files('bin', package = 'knitr')
which makes it easier to call knitr via command line under *nix (callknit input [output] [--pdf]
) -
the inline hooks respect
getOption('digits')
andgetOption('scipen')
now (see?options
); numbers returned from inline R code will be formatted according to these two options (see a demo at https://yihui.name/knitr/demo/output/) -
if you still use old Sweave syntax for chunk options, it is possible to write literal commas in chunk options now -- they have to be escaped by
\
, e.g.caption=hello\, world
; this will be parsed to'hello, world'
as a character string; of course this looks ugly and has limited power, so please please consider the new syntax! -
knit2pdf()
gained another argumentcompiler
which can be used to specify the program to compile the tex document to PDF, such as xelatex (#131) (thanks, Ramnath Vaidyanathan and Dennis Murphy) -
a new function
imgur_upload()
to upload images to imgur.com; it can be used in HTML or Markdown hooks so the output is a self-contained document which does not need additional image files;opts_knit$get('upload.fun'
) can use this function (#66) (thanks, Ramnath Vaidyanathan) -
a child document can be compiled individually with the LaTeX preamble borrowed automatically from a parent document using a new function
set_parent()
; see the help page for details (#136) (thanks, Helder Correia) -
to avoid
$$
around numbers in the inline output, we can useI()
to protect the numeric inline output, e.g.$x = \Sexpr{I(10^7)}$
gives$x = 10^7$
whereas\Sexpr{10^7}
gives$10^7$
(thanks, Kevin Middleton) -
the listings package is formally supported now (see
?render_listings
); the default style is borrowed fromSweavel.sty
written by Frank Harrell (#101) (thanks, Frank) -
new package option
cache.extra
which allows more objects to affect cache; see https://yihui.name/knitr/demo/cache/ (#134) -
new package option
child.path
to specify the search path of child documents relative to the parent document (#141) -
new package option
aliases
to set aliases for chunk options; see https://yihui.name/knitr/options (#144) -
new chunk options
fig.cap
,fig.scap
andfig.lp
to write captions, short captions, label prefix for the figure environment in LaTeX (#145) (thanks, Frank Harrell) -
new package option
eval.after
to set a character vector of chunk options which should be evaluated after a chunk is executed (thanks, Frank Harrell) -
a series of convenience functions
pat_rnw()
,pat_tex()
,pat_brew()
andpat_html()
to set built-in patterns (syntax) to read input
-
package option
eval.opts
has been dropped: all options of classessymbol
orlanguage
will be evaluated, so there is no need to specify which options to evaluate manually; remember, the chunk options are similar to function arguments, so you can use any valid R code there -
the default value for the
output
argument inknit()
is NULL now, so we can also provide output filenames tostitch()
andknit2pdf()
(#119) -
standard LaTeX messages are suppressed when a tikz plot is compiled to PDF so that we can see the knitr process more clearly
-
%\SweaveInput{}
will be ignored now (#150) -
results=asis
will no longer affect thechunk
hook (in the past, the chunk output was not wrapped in thekframe
environment whenresults=asis
); it only affects theoutput
hook now -
the package website allows comments now
-
the starting pattern of normal texts in an Rnw document is
^@\\s*%*
instead of^@\\s*$
now, meaning you can write@ % a comment
to end a code chunk (this is consistent with Sweave) -
the default value of the argument
output
ofknit()
will be a filename under the current working directory; in previous versions, the output file will be under the same directory as the input file; this change makes it possible to completely separate the input files and output files into different places, and hopefully will give users better experience in managing a whole collection of files (including child documents): put all source files in one place and output files in another place -
the package homepage is https://yihui.name/knitr now (the previous URL yihui.github.com/knitr will be automatically redirected to the new address)
- the object
opts_current
does not give the evaluated version of the current chunk options because it was created before the options are evaluated; this has been fixed andopts_current$get()
will give the expected values of options (thanks, Frank Harrell)
- number of downloads (https://github.com/yihui/knitr/downloads) of knitr documentation before I removed and updated them on GitHub: c(main = 1300, graphics = 549, themes = 130, beamer = 565, listings = 240, minimal = 160)
-
added support for including child documents in the main document (like
\SweaveInput{}
but with different implementations); see https://yihui.name/knitr/demo/child/ (#92) -
for inline R code, character results are returned as-is now (without
\texttt{}
) -
new function
purl()
as a wrapper toknit(..., tangle = TRUE)
which extracts R code from the input document (thanks to Dieter Menne's wife who suggested the function name) -
the error hook applies to inline R code when an error occurs in the inline R code, in which case knitr will not stop by default; instead, it writes the error message into the output (#85)
-
chunk option
split
also works for HTML output now using<iframe></iframe>
(#82) -
knit()
gained an argumenttext
as an alternative toinput
(#88) -
new chunk option
child
to include child documents into the main document (#92) -
chunk option
external
defaults toTRUE
now (wasFALSE
by default in the last version) -
added a new demo to show how to build package vignettes with knitr: https://yihui.name/knitr/demo/vignette/
-
added support to the
quartz()
device under Mac (#103); now thedev
option has more choices (see https://yihui.name/knitr/options) -
chunk option
echo
can take a numeric vector to select which R expressions to echo into the output now (#108); see https://yihui.name/knitr/options -
a new function
stitch()
which is a convenience function to insert an R script into a template and compile (to quickly create a report based on an R script) -
for a chunk hook to run, the corresponding chunk option no longer has to be
TRUE
; it can be any non-null values; this enables us to make use of the option value directly instead of only knowing it isTRUE
(see https://yihui.name/knitr/demo/cache/ for an example) -
knit()
will no longer write figure or cache files in the same directory as the input document; instead, these files are written in the current working directory (see ?knit) -
a new function
knit_env()
that makes the environment of the current chunk accessible to the user
-
the code used to merge global chunk options and local options was buggy for cache; it has been fixed now, so cache is more stable (#105), but users may see previously cached chunks being re-evaluated with this version, which should be regarded as a normal phenomenon, and on the second run, the cached chunks will not be evaluated again
-
fixed a buglet when using both options
out.width
andout.height
in Rnw (#113)
- first version of knitr: it covers most features in Sweave, cacheSweave and pgfSweave; see package homepage for documentation and examples: https://yihui.name/knitr/
-
knitr won an Honorable Mention prize (before it was formally released to CRAN) in the Applications of R in Business Contest hosted by Revolution Analytics: http://bit.ly/wP1Dii http://bit.ly/wDRCPV
-
in this NEWS file, #n means the issue number on GitHub, e.g. #142 is yihui#142