Releases: yihui/knitr
CHANGES IN knitr VERSION 1.11
NEW FEATURES
- 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)
MAJOR CHANGES
- 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)
BUG FIXES
CHANGES IN knitr VERSION 1.10.5
MAJOR CHANGES
- 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
CHANGES IN knitr VERSION 1.10
NEW FEATURES
-
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)
MAJOR CHANGES
- the minimal required version of R is 3.0.2 now, and you are recommended to use the latest version of R when possible
BUG FIXES
- 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
)
CHANGES IN knitr VERSION 1.9
NEW FEATURES
- 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)
MAJOR CHANGES
- 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)
MINOR CHANGES
- 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)
BUG FIXES
- 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)
CHANGES IN knitr VERSION 1.8
NEW FEATURES
- 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/orout.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')
generatesr 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)
BUG FIXES
- 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)
CHANGES IN knitr VERSION 1.7
NEW FEATURES
- 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')
BUG FIXES
- 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)
MAJOR CHANGES
-
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)
in 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)You may use the function below to clean up the redundant figure files:
#' Clean up figure files generated before knitr 1.7 #' #' This function finds figure files that may be redundant, e.g., knitr <= 1.6 #' generates foo.pdf for the chunk foo, and knitr >= 1.7 generates foo-1.pdf. If #' both foo.pdf and foo-1.pdf exist, foo.pdf might be redundant. #' @param dir the figure directory #' @param clean whether to remove the redundant figure files; make sure you take #' a look at the list if files detected before you clean them up clean_figures = function(dir = './figure', clean = FALSE) { # figure files that do not have a numeric suffix old1 = list.files(dir, '[^0-9][.][a-z]{3,4}$', full.names = TRUE) # or do not have - before suffix old2 = list.files(dir, '[^-][0-9]+[.][a-z]{3,4}$', full.names = TRUE) new1 = gsub('(.)([.][a-z]{3,4})$', '\\1-1\\2', old1) new2 = gsub('([^-])([0-9]+)([.][a-z]{3,4})$', '\\1-\\2\\3', old2) new = c(new1, new2) old = c(old1, old2) idx = file.exists(new) message('Possibly redundant files:') cat(paste('rm', paste(old, collapse = ' \\\n')), '\n') if (!any(idx)) return() if (clean) file.remove(old[idx]) else { message('Perhaps you should remove these files:') cat(old[idx], sep = '\n') } }
-
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 behavior of this engine is to evaluate the code, instead of printing JavaScript; if you want the old behavior, 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)
MINOR CHANGES
- 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$
CHANGES IN knitr VERSION 1.6
NEW FEATURES
- 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 behavior 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 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)
BUG FIXES
- 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)
MAJOR CHANGES
- 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 cha...
CHANGES IN knitr VERSION 1.5
NEW FEATURES
- 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)
BUG FIXES
- 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
MAJOR CHANGES
- 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)
MINOR CHANGES
- 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 in 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)
CHANGES IN knitr VERSION 1.4
NOTE
- 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
NEW FEATURES
- 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
: http://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)
MAJOR CHANGES
- 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: http://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
MINOR CHANGES
- 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
BUG FIXES
- 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)
CHANGES IN knitr VERSION 1.3
NEW FEATURES
- 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)
BUG FIXES
- 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)
MAJOR CHANGES
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)
MINOR CHANGES
- 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
MAINTAINENCE
- 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 (http://cran.r-project.org/package=testit)
MISC
- knitr becomes an affiliated project of FOAS (Foundation for Open Access Statistics): http://www.foastat.org/projects.html