Skip to content

knitr 1.38

Compare
Choose a tag to compare
@yihui yihui released this 25 Mar 14:16
· 316 commits to master since this release

NEW FEATURES

  • The chunk option file can take a vector of file paths now, i.e., this option can be used to read more than one file (e.g., file = c("foo.R", "bar.R").

  • Added a new engine named exec (#2073) to execute an arbitrary command on the code chunk, e.g.,

    ```{exec, command='Rscript'}
    1 + 1
    ```

    The above code chunk executes the Rscript command with the chunk body as its input (which basically means executing the R code in a new R session). See the example #124 in the repo https://github.com/yihui/knitr-examples for more info.

    There exists several command-based engines in knitr, such as awk, bash, perl, go, and dot, etc. This new exec engine provides a general mechanism to execute any command that users provide. For example, the code chunk

    ```{bash}
    echo 'Hello world!'
    ```

    is equivalent to the chunk using the exec engine and the bash command:

    ```{exec, command='bash'}
    echo 'Hello world!'
    ```

    With this new engine, we no longer need to provide or maintain other simple command-based engines. For example, to support TypeScript (#1833), we only need to specify command = 'ts-node' with the exec engine.

    If the command has significant side-effects (e.g., compile source code to an executable and run the executable, or generate plots to be included in the output), it is also possible to create a new engine based on the exec engine. The example #124 in the knitr-examples repo has provided a gcc example.

    We'd like to thank @TianyiShi2001 for the inspiration (#1829 #1823 #1833).

  • Added a new engine ditaa based on the exec engine to convert ASCII art diagrams to bitmaps via the ditaa command (thanks, @kondziu, #2092).

  • Added two new chunk options, class.chunk and attr.chunk, for R Markdown output. These options can enclose the whole chunk output (source and results) in a fenced Div. Their syntax follows other chunk options with the similar names class.* and attr.* (e.g., class.source and attr.source). For example, class.chunk = "foo" would wrap the chunk output inside ::: {.foo} and ::: (thanks, @atusy, #2099).

  • Added a new chunk option lang to set the language name of a code chunk. By default, the language name is the engine name. This is primarily useful for syntax highlighting the source chunks in Markdown-based output. Previously the lang option was only available to a few engines such as verbatim and embed. Now it is available to all engines.

  • Added a new wrapper function rnw2pdf(). It allows users to specify an arbitrary output file path, clean the intermediate files, and stop when any error occurs in knitting (thanks, @shrektan, #2113).

  • New calling.handlers option for opts_chunk$set() to register calling handlers within chunks. See ?evaluate::new_output_handler for details.

MAJOR CHANGES

  • The minimal required version of R was bumped from 3.2.3 to 3.3.0 (thanks, @essemenoff, #2100).

  • The working directory under which chunk options are evaluated has been changed to the directory of the source document by default. If the package option root.dir is set to a different directory, that directory will be used as the working directory (#2081).

  • include_graphics() will expand ~ in the image paths now and also warn against absolute paths (thanks, @kcarnold, #2063).

  • opts_chunk$set() returns values of old chunk options after setting new chunk options now, instead of returning NULL, which can make it a little simpler to reset chunk options, e.g., you can temporarily change a few chunk options and save them with old = opts_chunk$set(error = FALSE, fig.height = 3), and reset them later with opts_chunk$set(old). This works for any other objects in knitr that have the $set() methods, such as opts_knit, opts_hooks, knit_hooks, knit_engines, and so on.

MINOR CHANGES

  • The chunk option fig.scap has been added to eval.after in opts_knit (thanks, @knokknok, #2061).

BUG FIXES