Returns a character vector for the code chunk to plot a figure
Source:R/chunk_templates.R
tpl_plot_figure.Rd
Returns a character vector for the code chunk to plot a figure
Usage
tpl_plot_figure(
chunk_label,
figure_caption,
figure_height,
font_family = get_font_df()[["family"]],
function_call = "RUBer::plot_figure",
tab_placeholder = "PLACEHOLDER_TAB",
suppress_warnings = FALSE
)
Arguments
- chunk_label
Character, chunk label
- figure_caption
Character, figure caption
- figure_height
Numeric, figure height in inches
- font_family
Character, the font family to use for all plots, defaults to
get_font_df()[["family"]]
- function_call
Character, defaults to
RUBer::plot_figure
- tab_placeholder
Character, pandoc does not support the insertion of tabs, which is why a placeholder text is needed that will get replaced with tabs in post-processing, defaults to "PLACEHOLDER_TAB"
- suppress_warnings
Boolean, whether to suppress the warnings generated by this code chunk, defaults to
FALSE
.
Examples
# Returns code chunk as list
code_chunk_list <- tpl_plot_figure(
chunk_label = 1L,
figure_caption = "Caption for figure 1",
figure_height = 4.2
)
# Unlist
code_chunk_vector <- unlist(
code_chunk_list
)
# Display code chunks as they will be written to the Rmd
writeLines(
code_chunk_vector
)
#>
#> ```{r fig-1, fig.cap = 'PLACEHOLDER_TABCaption for figure 1', fig.height = 4.2, fig.showtext = TRUE, warning = TRUE}
#> RUBer::plot_figure(df_fig, font_family = 'DejaVu Sans')
#> ```
# The function is vectorized, so you can do this:
tpl_plot_figure(
chunk_label = c(
1L,
2L
),
figure_caption = c(
"Caption for figure 1",
"Caption for figure 2"
),
figure_height = c(
4.2,
3.5
)
)
#> [[1]]
#> [[1]][[1]]
#> [1] "\n```{r fig-1, fig.cap = 'PLACEHOLDER_TABCaption for figure 1', fig.height = 4.2, fig.showtext = TRUE, warning = TRUE}"
#> [2] "RUBer::plot_figure(df_fig, font_family = 'DejaVu Sans')"
#> [3] "```"
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [1] "\n```{r fig-2, fig.cap = 'PLACEHOLDER_TABCaption for figure 2', fig.height = 3.5, fig.showtext = TRUE, warning = TRUE}"
#> [2] "RUBer::plot_figure(df_fig, font_family = 'DejaVu Sans')"
#> [3] "```"
#>
#>