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

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

Examples

# 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}")) } )