render_report: Render a single parametric report as Word file

View source: R/report.R

render_reportR Documentation

Render a single parametric report as Word file

Description

The render_report function is called once for each report to be created. render_report_safely wraps render_report in purrr::safely.

Usage

render_report(
  p_df = filter_report(df = RUBer::df_example, report_nr = 6L),
  p_df_stg = NULL,
  report_nr = 6L,
  rmd_template = fs::path_package(package = "RUBer", "rmarkdown", "templates",
    "datenreport-2022", "skeleton", "skeleton.Rmd"),
  output_directory = fs::path_temp(),
  output_filename = fs::path_file(fs::file_temp(pattern = "RUBer_report_", ext =
    ".docx")),
  title = "Title",
  author = "Author",
  date = format(Sys.Date(), format = "%B %Y"),
  font_file = "RubFlama-Regular.ttf",
  path_figure_template = fs::file_temp(pattern = "figure_template_", ext = ".Rmd"),
  post_process = TRUE,
  quiet = FALSE
)

render_report_safely(...)

Arguments

p_df

Data frame containing the data for all reports

p_df_stg

Optional data frame with information on cases

report_nr

Report number of the report

rmd_template

Path to the R Markdown File for that report, defaults to Datenreport 2022 template from RUBer package

output_directory

Output directory for the rendered report, defaults to here::here("output")

output_filename

Output filename for the rendered report, defaults to p_df[[1, "file_name"]]

title

Character, title for the title page

author

Character, author for the title page

date

Date of the report displayed on the title page, defaults to format(Sys.Date(), format= "%B %Y").

font_file

Character, font file to use in all plots, defaults to "RubFlama-Regular.ttf"

path_figure_template

Character, file path to write the dynamically generated figure chunks to file (useful for debugging purposes). Defaults to fs::file_temp(pattern = "figure_template_", ext = ".Rmd")

post_process

Boolean, whether post_process gets called on the output file

quiet

An option to suppress printing during rendering from knitr, pandoc command line and others. Passed on to rmarkdown::render

...

Arguments passed on to render_report

Value

Invisibly returns p_df

Examples

# Check if pandoc is available in the minimum required version
pandoc_available <- rmarkdown::pandoc_available(
  version = "2.0",
  error = FALSE
)

if(pandoc_available){

  # Get paths for skeleton.Rmd
  skeleton_location <- fs::path_package(
    package = "RUBer",
    "rmarkdown",
    "templates",
    "datenreport-2022",
    "skeleton",
    "skeleton.Rmd"
  )

  # Session based output directory
  output_directory <- fs::path_temp()

  # File name for the report output file
  output_filename <- fs::path_file(
    fs::file_temp(
      pattern = "RUBer_report_",
      ext = ".docx"
    )
  )

  # Full path to output file
  path_report_docx <- fs::path(
    output_directory,
    output_filename
  )

  # Create output directory
  fs::dir_create(
    output_directory
  )

  # Copy all files in the skeleton folder to the output directory
  fs::file_copy(
    path = fs::dir_ls(
      fs::path_dir(
        skeleton_location
      )
    ),
    new_path = output_directory
  )

  # Render the report in the temporary output directory
  render_report(
    rmd_template = skeleton_location,
    output_directory = output_directory,
    output_filename = output_filename
  )
}

RichardMeyer-Eppler/RUBer documentation built on June 2, 2022, 7:24 p.m.