hook_title_comment: Prepend title comment to chunks

Description Usage Arguments See Also Examples

View source: R/hook_title_comment.R

Description

Prepend title comments to each chunks. By default, title is the name of the corresponding chunk engines.

Usage

1
2
3
4
5
6
hook_title_comment(
  trigger = "title",
  default = "{engine}",
  args = list(),
  .set = TRUE
)

Arguments

trigger

A name of chunk option triggers the hook.

default

A string or function as a default value of the triggering chunk option. If string, the value is given to glue::glue, and evaluates the expression by setting chunk options as an environment, and then automatically commented out. If function, it must have options parameter which receives chunk options, and return a string.

args

A list of arguments given to glue::glue() or callable default.

.set

TRUE or FALSE to set a default value and a hook to the trigger.

See Also

comment_title(), comment_out(), comment_syntax()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Set hook which comments engine names of each chunks at the beginning.
hook_title_comment()

# Customize format
# For R chunks, let title comment be something like "chunk-label.R".
# Otherwise, fall back to the default behavior.
hook_title_comment(
  default = function(options) {
    if (options$engine == "R") {
      return(sprintf("# %s.%s", options$label, options$engine))
    }
    return(comment_title(options, template = "{engine}"))
  }
)

atusy/chunkhooks documentation built on Nov. 30, 2021, 10:32 a.m.