Skip to content

CHANGES IN knitr VERSION 1.6

Compare
Choose a tag to compare
@yihui yihui released this 25 May 06:28
· 2963 commits to master since this release

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 to spin() 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 to write_bib() so that we can customize the prefix for bib entries; we can also set options(knitr.bib.prefix = 'a_string') so that write_bib() uses this global option as the default value for prefix (thanks, Michael Friendly)
  • the chunk option dev.args will be passed to the pdf recording device if pdf is also in the chunk option dev (note the recording device can be different with the actual drawing device); for example, you can pass a different pointsize 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 parameter precious to TRUE (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; if collapse = 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 when fig.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 is print() (or show() 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 options echo and eval -- when either one is FALSE, 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 in hook_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 when cache is enabled; for really large objects, you may need cache.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 for kable(x) can also be a vector of length ncol(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 argument padding to specify the inner padding of table cells using spaces (thanks, @gavril0, #699)
  • added a new vignette engine called rmarkdown, which uses rmarkdown::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 vignette knit_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 the fig.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 in knit2wp() 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. for knit_hooks$set(foo = hook_foo), hook_foo can be of the form function(before, options, envir, name), where name == 'foo' (thanks, Thell Fowler, #733)
  • all the four arguments before, options, envir, and name for a chunk hook are optional now, e.g. you can define a hook function of the form function(before, options), function(before, name, envir), and so on
  • added two read-only chunk options out.width.px and out.height.px, which are the numbers of pixels calculated from fig.width and fig.height (which have units in inches), respectively, and the chunk options out.width and out.height can override the calculated natural size
  • added a new argument encoding to the pandoc() 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 the align 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 option dev is a vector of length greater than one (thanks, Ashley Manton, #703)
  • hook_rgl() did not work with the chunk option fig.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 is FALSE now, which means the R source code in chunks will no longer be reformatted by formatR::tidy.source() by default; this feature must be explicitly turned on by tidy=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 in pandoc() has changed: it defaults to the t 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 options opts_knit$set(foo = value) before knitting a document; now the prefix for package options has been changed to knitr.package., i.e. we should set options(knitr.package.foo) to achieve opts_knit$set(foo); besides, it is also possible to change the default chunk options using options(knitr.chunk.foo) now, but you are warned that this may bring reproducibility issues, so please use with care

MINOR CHANGES

  • 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 the kable() 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 in options() (thanks, @rmatev, #708)