knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

This article introduces additional knit engines. Load atusydown package primarily to enable features described here.

library(atusydown)

To learn more about language engines, refer to "Other language engines" section of the "R Markdown: The Definitive Guide".

code <- function(nm) paste(knitr:::knit_code$get(nm), collapse = "\n")
library(atusydown)

glue

The glue engine is useful in programatically writing texts. As documented in ?glue::glue,

Expressions enclosed by braces will be evaluated as R code. Long strings are broken by line and concatenated together. Leading whitespace and blank lines from the first and last lines are automatically trimmed.

For example, let's substitute {name} by "Atusy".

First use r engine like below.

name <- "Atusy"

And then use glue engine like below. Note that echoes are suppressed.

```{glue`r "}"`
`r code("glue-brace")`
```

```{glue glue-brace}

My name is {name}. This output is powered by glue package!

Nice text!
The output text is rendered as Pandoc's markdown.

Extra arguments of `glue::glue()` can be controlled by specifying `glue.args`.
A following example 
  replaces a expression enclosed by percents (`%` and `%`) 
  instead of default braces (`{` and `}`)

````{.text}
```{glue, glue.args = list(.open = "%", .close = "%")`r "}"`
`r code("glue-percent")`
```{glue glue-percent, glue.args = list(.open = "%", .close = "%")}
> **My name is %name%.**
This output is powered by glue package!
```

## `footnote` and `fn`

A `footnote` engine and its alias `fn` generates footnote whose label is
inherited from chunk label[^fn-footnote].
The `footnote` engine is powered by `glue::glue()`,
so that options are same as those of the [glue](#glue) engine.
Note that echoes are suppressed.

````text
```{fn fn-footnote`r "}"`
knitr:::knit_code$get("fn-note")
```

``{fn fn-footnote} This is a footnote generated byfn` engine.

## `note`

The `note` engine is for writing personal notes.
Notes are excluded from output documents except for
reveal.js slides by `revealjs::revealjs_presentation()`.
Note that echoes are suppressed.

When knitting reveal.js slides,
notes are wrapped by `aside` tags with a `note` class like below.

````
```{note`r "}"`
Here's some note.
```html
<aside class = "note">Here's some note.</aside>
```

Enable `notes` plugin for example by a following YAML front matter
to use speaker notes.
For more documentations about plguins refer 
[README of `rstudio/revealjs`](https://github.com/rstudio/revealjs#reveal-plugins).

```yaml
---
output:
  revealjs::revealjs_presentation:
    self_contained: false
    reveal_plugins: ["notes"]
---
```

## `opts`

The `opts` engine returns chunk options of a current chunk.

By default, all the available options are returned.
The output of `opts` can be limited by specifying either `"diff"` or `"src"` to
a chunk option called `opts.show`.

The output of `opts` is by default sorted by names.
The sorting can be disabled by specifying `opts.sort = FALSE`.

Note that echoes are suppressed.

### Show all the chunk options (default)

````{.text}
```{opts`r "}"`
`r code("options")`
```

```{opts options} The content of chunk is ignored.

### Show options different from `opts_chunk$get()` by `opts.show = "diff"`

Specifying `ops.show = "diff"` as a chunk option returns 
chunk options of the source chunk which have different values from
`knitr::opts_chunk$get()`.

````{.text}
```{opts opts-diff, foo = "bar", opts.show = "diff"`r "}"`
```{opts opts-diff, foo = "bar", opts.show = "diff"}

```

### Show input options in the chunk by `opts.show = "src"`

Specifying `opts.show = "src"` as a chunk option 
returns chunk options that are set in the source chunk.

``{opts opts-src, opts.show = "src"r "}"`

````

```{opts opts-src, opts.show = "src"}


atusy/atusydown documentation built on Sept. 1, 2020, 3:37 a.m.