getUnitReport: Generate unit report

Description Usage Arguments Details Value Examples

View source: R/coin_resultstable.R

Description

Generates a scorecard for a given unit using an R Markdown template.

Usage

1
2
3
4
5
6
7
getUnitReport(
  COIN,
  usel,
  out_type = ".html",
  outdir = NULL,
  rmd_template = NULL
)

Arguments

COIN

A COIN

usel

A selected unit code, or a character vector of unit codes (for multiple reports).

out_type

A string specifying the output type. Can be either ".docx" (Word), ".pdf" or ".html". IMPORTANT: if the template includes interactive plots (e.g. the iplot() functions from COINr), writing to .docx or .pdf will not work unless you have installed the webshot package. To do this, run: install.packages("webshot") webshot::install_phantomjs()

outdir

Character string specifying the output directory (defaults to current working directory).

rmd_template

A character string specifying the full file path to an R Markdown template which is used to generate the report. If this is not specified, defaults to COINr's inbuilt template example.

Details

Most likely you will want to customise the template which can be found in the COINr installed package directory under /UnitReport. Currently, a few examples are given, such as some charts and basic summary statistics.

This function will render the unit report to either pdf, html or word doc. As mentioned below, if you have HTML widgets such as interactive plotly plots, or COINr iplot() functions, you will need to install the webshot package to be able to render to pdf or word formats.

To customise the template, copy the .rmd template found in /UnitReport and alter it, then point the rmd_template argument to your new template.

Note that this function is particularly useful for generating a large number of reports, e.g. we can generate reports for all units at once using a for loop, purrr::map or apply() or similar.

Value

Markdown document rendered to HTML, pdf or Word. This function requires Pandoc to be installed. If Pandoc is not found, then it returns a warning and a printed message (string).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# build ASEM COIN up to aggregation
ASEM <- build_ASEM()
# Generate a unit report for NZ
# This is written to the temporary directory to avoid polluting other directories
# during automated testing.
# It will be deleted at the end of the R session.
# Normally you would set the directory to somewhere else to save the resulting files
getUnitReport(ASEM, usel = "NZL", out_type = ".html", outdir = tempdir())
# You can find this file in the temporary directory:
print(tempdir())
# We will now delete the file to keep things tidy in testing
unlink(paste0(tempdir(),"\\NZL_report.html"))

COINr documentation built on Nov. 30, 2021, 9:06 a.m.