Skip to content

CHANGES IN knitr VERSION 0.7

Compare
Choose a tag to compare
@yihui yihui released this 25 May 21:31
· 4769 commits to master since this release

NEW FEATURES

  • 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 http://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 after knit() 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 http://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' (default NULL) 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 calling ghc (#336) (thanks, Michel Kuhlmann)
  • added support to Andre Simon's highlight through the option engine='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 and results are also respected when the language is not R, e.g. for a Python code chunk with eval=FALSE, the code will not be evaluated, or for a Ruby chunk with results='hide', the output will be hidden (#293) (thanks, Ramnath Vaidyanathan)
  • chunk options out.width, out.height and out.extra also work for plots in HTML and Markdown output now, e.g. out.width='200px' or out.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 to hook_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() and hook_scianimator() which can be set as the package option opts_knit$get('animation.fun') and create animations via the R2SWF package or the SciAnimator library (see animation::saveHTML) (thanks, Taiyun Wei)
  • a new function image_uri() to create data URIs for image files; we can set opts_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 option opts.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 using optipng (#272) (thanks, Winston Chang)
  • added a new output hook named document in knit_hooks (see knit_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 whote output before writing it to the output file
  • a new function rst2pdf() which uses the program rst2pdf to convert reST documents to PDF; it is also supported by knit2pdf() when compiler='rst2pdf' (#300) (thanks, Alex Zvoleff)

BUG FIXES

  • fixed #286: messages (including warnings and errors) are guaranteed to be ended by \n, so even when chunk option comment=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 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 where opts_chunk$set() is (thanks, Guy Lebanon) (http://bit.ly/MexHXd)
  • fixed #332: calling purl() inside a source document when knit() the same document could cause clashes; now it is safe to put purl() inside a source document and knit() it
  • fixed #342: when eval=FALSE, line breaks in the source code were missing

MAJOR CHANGES

  • 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 named as unnamed-chunk-1 and unnamed-chunk-2; in previous versions, both will be named as unnamed-chunk-1 which can cause clashes of cache and figure files
  • the function build_dep() was renamed to dep_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

MINOR CHANGES

  • the LaTeX environment kframe was updated so that it can be used in other environments such as center or tabular (#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 in knit2html() is passed to markdownToHTML() in the markdown package instead of knit(); this allows us to pass more arguments to control the rendering of HTML output, e.g. knit2html(input, fragment.only = TRUE) (#333) (thanks, @bart6114)

DOCUMENTATION