This function creates the Rmd file which will be rendered in a specific format.
Usage
generate_rmd_file(
content,
output_format = c("word", "pdf", "html", "word_document", "pdf_document",
"html_document"),
font_size = 12,
code = TRUE,
font_path = get_fira_path(),
word_template_path = get_word_template_path(),
...
)
Arguments
- content
a string. The body of the Rmd file (for example code or text)
- output_format
a string representing the output format. The values
"pdf"
,"html"
or"word"
and their knitr equivalent"pdf_document"
,"html_document"
or"word_document"
are accepted.- font_size
a numeric. The font size, only available in pdf format.
- code
a boolean. Should the
content
string have to be inserted in R chunk or is it just text? Default is TRUE (so thecontent
will be inserted in R chunk).- font_path
a string. The path to the font used to render code chunks. It should link to a
.ttf
file. Only available in pdf format.- word_template_path
a string. The path to the word template file used when rendering with word. By default, the template used is the one included in the package. Only used with word output.
- ...
other arguments passed to R chunk (for example
eval = TRUE
,echo = FALSE
...)
Details
More information about the argument ... in the documentation of the
function render_code
.
Examples
generate_rmd_file(content = "Bonjour tout le monde",
code = FALSE,
output_format = "word")
#> [1] "---"
#> [2] "title: \"Format code\""
#> [3] "output:"
#> [4] " word_document:"
#> [5] " highlight: arrow"
#> [6] " reference_docx: \"/home/runner/work/_temp/Library/TBox/extdata/template.docx\""
#> [7] "code-block-bg: true"
#> [8] "code-block-border-left: \"#31BAE9\""
#> [9] "---"
#> [10] ""
#> [11] ""
#> [12] ""
#> [13] ""
#> [14] "## Running Code"
#> [15] ""
#> [16] ""
#> [17] "Bonjour tout le monde"
#> [18] ""
generate_rmd_file(content = "print(AirPassengers)",
code = TRUE,
output_format = "pdf",
eval = TRUE,
echo = FALSE)
#> [1] "---"
#> [2] "title: \"Format code\""
#> [3] "output:"
#> [4] " pdf_document:"
#> [5] " highlight: arrow"
#> [6] " fig_crop: true"
#> [7] " latex_engine: xelatex"
#> [8] " keep_tex: true"
#> [9] "code-block-bg: true"
#> [10] "code-block-border-left: \"#31BAE9\""
#> [11] "---"
#> [12] ""
#> [13] "\\fontsize{12}{12}"
#> [14] "\\setmonofont[ExternalLocation=/home/runner/work/_temp/Library/TBox/extdata/FiraCode/]{FiraCode-Regular.ttf}"
#> [15] ""
#> [16] "## Running Code"
#> [17] ""
#> [18] "```{r, eval = TRUE, echo = FALSE}"
#> [19] "print(AirPassengers)"
#> [20] "```"
generate_rmd_file(content = "plot(AirPassengers)",
code = TRUE,
output_format = "html_document",
eval = FALSE,
echo = TRUE)
#> [1] "---" "title: \"Format code\""
#> [3] "output:" " html_document:"
#> [5] " highlight: arrow" "monofont: \"Fira Code\""
#> [7] "code-block-bg: true" "code-block-border-left: \"#31BAE9\""
#> [9] "---" ""
#> [11] "" ""
#> [13] "" "## Running Code"
#> [15] "" "```{r, eval = FALSE, echo = TRUE}"
#> [17] "plot(AirPassengers)" "```"