R/render_MABM.R

Defines functions render_MABM

render_MABM <- function(out_dir, year, station, stn_start_yr,
                        route_path, survey_path, bat_path, spp_path, key) {

  # Need better error catching, but this will do for now...
  if (is.null(station)) stop("You must provide a MABM station.")

  rmd_document <- system.file("extdata", "MABM_report_template.Rmd", package = "MABMreportr")

  station_short <- shorten_station(station)

  fn <- paste("MABM", station_short, year, sep = "_")
  out_file <- paste(fn, "pdf", sep = ".")

  rmarkdown::render(rmd_document, output_dir = out_dir,
                    output_file = out_file,
                    params = list(year = year,
                                  station = station,
                                  stn_start_yr = stn_start_yr,
                                  route_path = route_path,
                                  survey_path = survey_path,
                                  bat_path = bat_path,
                                  spp_path = spp_path,
                                  goog_API_key = key),
                    quiet = TRUE)
  message("Created ", year, " MABM annual report for ", station, ":\n    ",
          tools::file_path_as_absolute(file.path(out_dir, out_file)))
}
adamdsmith/MABMreportr documentation built on Feb. 1, 2023, 11:17 p.m.