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

The output formats of unilur are able to render chunks in coloured boxes.

Solution chunks

Solution chunks (using the option solution = TRUE) are only visible when using a solution output (tutorial_html_solution or tutorial_pdf_solution) and are rendered by default as green boxes. In the HTML output format these boxes are in addition collapsible.

`r ''````{block, solution = TRUE}
This is the solution...
```

```{block, solution = TRUE} This is the solution...

## Put the chunk output in customized boxes

You can render your own boxes using the following chunk options defined in `unilur`:

- **box.title**: The title of the box
- **box.body**: A list containing `fill` (background) and/or `colour` (text if applicable _e.g._ block chunk) to define the colours of the body. Use the _R_ colour specifications (see `grDevices::col2rgb()`).
- **box.header**: A list containing `fill` and/or `colour` to define the colours of the header.
- **box.collapse**: The collapsible status of the box (only applicable to `tutorial_html*` formats)`:
    + `NULL`: the box is not collapsible
    + `TRUE`: the box is collapsed
    + `FALSE`: the box is not collapsed but collapsible
- **box.icon**: optional [Font Awesome](https://fontawesome.com/) or [Ionicon](https://ionicons.com/v2/cheatsheet.html) name. The character sequence should start with either `fa-` for [Font Awesome](https://fontawesome.com/) icons or `ion-` for [Ionicons](https://ionicons.com/v2/cheatsheet.html). Alternatively you can use a function defined in a package such as [`icon`](https://github.com/ropenscilabs/icon).

Example of a coloured box:

    `r ''````{block, box.title = "You can add a title", box.body = list(fill = "lightblue"), box.header = list(fill = "red", colour = "white")}
    A custom box
    ```

```{block, box.title = "You can add a title", box.body = list(fill = "lightblue"), box.header = list(fill = "red", colour = "white")}
A custom box

Example of a coloured box using an icon:

`r ''````{block, box.title = "Title and icon", box.body = list(fill = "lightblue"), box.icon = "fa-star"}
This box contains an icon in the header...
```

```{block, box.title = "Title and icon", box.body = list(fill = "lightblue"), box.icon = "fa-star"} This box contains an icon in the header...

## Define shortcuts

`knitr` allows to create option templates to set multiple chunk options that are frequently used (using the `knitr::opts_template()` function and [`opts.label`](https://yihui.name/knitr/options/#option-templates) chunk option). To demonstrate how to use this feature to create box themes, let's define an alias named _alert_ to set multiple `box.*` chunk options:

```r
knitr::opts_template$set(alert = list(box.title = "Watch out!",
                                      box.body = list(fill = "#fa5b42", colour = "#fdf6d4"),
                                      box.collapse = TRUE,
                                      box.icon = "fa-exclamation-triangle"))

Now set the opts.label chunk option to the alias you just created:

`r ''````{block, opts.label = "alert"}
This is an important message...
```

```{block, opts.label = "alert"} This is an important message...

## Change the solution box theme

When you use the `solution` chunk option to define solution chunks, `unilur` uses the "solution" option template to render the box:

    `r ''````{block, opts.label = "solution"}
    This is how the solution box looks like
    ```

```{block, opts.label = "solution"}
This is how the solution box looks like

You can check the default values used for the "solution" option template:

str(knitr::opts_template$get("solution"), give.attr = FALSE)

Thus you can override the settings:

knitr::opts_template$set(solution = list(box.title = "Look at the result",
                                         box.body = list(fill = "pink"),
                                         box.collapse = TRUE))
`r ''````{block, solution = TRUE}
This is how the solution box looks like
```

```{block, opts.label = "solution"} This is how the solution box looks like

```r
# flush fa icon dependency: pkgdown already loads fa from cdn
knitr::knit_meta()


koncina/unilur documentation built on Sept. 24, 2021, 12:24 a.m.