| Title: | Chunk Hooks for 'R Markdown' | 
| Version: | 0.0.1 | 
| Maintainer: | Atsushi Yasumoto <atusy.rpkg@gmail.com> | 
| Description: | Set chunk hooks for 'R Markdown' documents https://rmarkdown.rstudio.com/, and improve user experience. For example, change units of figure sizes, benchmark chunks, and number lines on code blocks. | 
| License: | MIT + file LICENSE | 
| URL: | https://chunkhooks.atusy.net, https://github.com/atusy/chunkhooks | 
| Encoding: | UTF-8 | 
| Language: | en-US | 
| LazyData: | true | 
| RoxygenNote: | 7.1.1 | 
| Imports: | knitr, measurements, prettyunits | 
| Suggests: | spelling, testthat, rmarkdown | 
| VignetteBuilder: | knitr | 
| NeedsCompilation: | no | 
| Packaged: | 2020-08-01 13:53:15 UTC; rstudio | 
| Author: | Atsushi Yasumoto | 
| Repository: | CRAN | 
| Date/Publication: | 2020-08-05 15:00:02 UTC | 
Benchmark chunks
Description
hook_benchmark sets a hook to benchmark chunks with the benchmark=TRUE
option. The name of the trigger chunk option can be changed via the
chunk_option parameter. The result is printed right after chunk outputs.
See examples for the default printing format by format_benchmark.
Usage
hook_benchmark(
  trigger = "benchmark",
  default = NULL,
  format = format_benchmark,
  .set = TRUE
)
format_benchmark(result, options)
benchmarks
Arguments
| trigger | A name of chunk option that triggers benchmark (default:
 | 
| default | A default value for the chunk option that  | 
| format | A function to format a benchmark result (default:
 | 
| .set | 
 | 
| result | A result of benchmark | 
| options | A list of current chunk options | 
Format
An object of class environment of length 0.
Details
benchmarks records the results of benchmarks from chunks as a list named by
chunk labels. If one requires complex formatting of benchmark results, then
suppress automatic formatting by hook_benchmark(format = NULL). Then,
retrieve benchmark results from benchmarks[["chunk-label"]]. Furthermore,
format can happen conditionally by utilizing current chunk options via
the second argument of the formatting function.
Value
invisible hook function
Examples
# Set a hook that triggers benchmarks if the `time` chunk option is not `NULL`.
hook_benchmark("time")
# Example of the default output format
# Input is sec. Output is prettified.
format_benchmark(1234, options = list(label = "example-chunk"))
Change the unit of figure size
Description
By default, figure size of R Markdown is specified with inches. This function changes the default unit.
Usage
hook_figure_unit(unit = "mm", .set = TRUE)
Arguments
| unit | A string of an unit (default: "mm"). Available units follow.
 | 
| .set | 
 | 
Details
As a side effect, fig.retina is set to NULL because of
https://github.com/yihui/knitr/issues/1876.
Value
invisible hook function
Examples
hook_figure_unit('mm')
Number lines on code blocks
Description
Number lines on code blocks created by chunks, i.e. source, output, message, warning, and/or error.
Usage
hook_numberLines(targets = "source", .set = TRUE)
Arguments
| targets | A character vector specifying what kind of code blocks
automatically number lines (default:  | 
| .set | 
 | 
Value
invisible hook function
Examples
hook_numberLines("source")