R/report.R

Defines functions report

Documented in report

#' Creates a basic data quality report.
#'
#' @param data The data frame.
#' @param qc QC errors, if not provided some tests are done on the provided
#'   data.
#' @param file Output file (default is "report.html").
#' @param dir Directory where to store the file (default is
#'   \code{rappdirs::user_cache_dir("obistools")}).
#' @param view Logical, show the report in a browser after creation (default
#'   \code{TRUE}).
#' @param topnspecies Integer, number of species ordered by number of records
#'   for which you want to do the outlier analysis
#' @return Returns the full path to the generated html report.
#' @examples
#' \dontrun{
#' report(abra)
#' }
#' @export
report <- function(data, qc = NULL, file = "report.html", dir = NULL, view = TRUE, topnspecies = 20) {

  reportfile <- system.file("", "report.Rmd", package = "cerberus")

  if (is.null(qc)) {
    qc <- bind_rows(
      plot_map_leaflet(data, report = TRUE),
      check_datatype(data, report = TRUE),
      check_onland(data, report = TRUE),
      check_depth(data, report = TRUE),
      check_outliers(data, report = TRUE),
      match_wormstaxa(data, report = TRUE)
    )
    qc <- distinct(qc)
  }
  if(is.null(dir) || is.na(dir)) dir <- rappdirs::user_cache_dir("cerberus")
  if(!dir.exists(dir)) dir.create(dir, recursive = TRUE)
  outputfile <- rmarkdown::render(reportfile, output_file = file, output_dir = dir, params = list(data = data, qc = qc))
  if(view) {
    utils::browseURL(outputfile)
  }
  return(outputfile)
}
sharksmhi/tryout documentation built on Dec. 27, 2019, 5:34 a.m.