Write R chunk to template

add_chunk(
  x,
  echo = "false",
  warnings = "false",
  eval = "true",
  label = NULL,
  add_option = FALSE,
  chunk_op = NULL
)

Arguments

x

Content to be written within the R chunk. Wrap in quotation marks ("").

echo

TRUE/FALSE; Option to repeat code in the document. Default is false.

warnings

TRUE/FALSE; Option to report warnings in the console during render. Default is false.

eval

TRUE/FALSE; Option to evaluate the chunk. Default is true.

label

The name of the chunk in the 'label:' section of the R code chunk. This should be in snakecase (i.e., in which words are written in lowercase and connected by underscores).

add_option

TRUE/FALSE; Option to add additional chunk options. Default is false.

chunk_op

List of chunk options to add. For example: c("output: true", "error: false)

Value

Write an additional R chunk into the template using this function. The code can be written as usual, just remember to put it entirely in quotes for the function to render it properly

Examples

add_chunk("plot(cars$speed, cars$distance)")
#> [1] "```{r} \n#| echo: false \n#| warning: false \n#| eval: true \nplot(cars$speed, cars$distance)\n``` \n"