R/build_enr_report.R

Defines functions build_enr_report

Documented in build_enr_report

#' Function which bulid template for ENR report
#' 
#' @param file Rmd file name which we want to create.
#' @param subdir subdirectory name where we want to store our report. Default value: 'reports'
#' @examples 
#' \dontrun{
#' build_enr_report('001_initial_report')
#'      }

build_enr_report <- function(file, subdir = "reports"){
  
  file_name <- paste0(subdir, "/", file, ".Rmd")
  files_cnt <- list.dirs(subdir) %>% length()
  
  if (files_cnt == 1) {
    rmarkdown::draft(file_name, template = "enr_report", package = "ENRanalytics", edit = FALSE)
    load_html_files(path = report_system_file(''))
    report_show(subdir, file, paste0(file, '.Rmd'))
  }
  
  else if (files_cnt == 0) {
    warning(paste0("There is no subdirectory '", subdir, "' in your project. Please use correct name."), call. = FALSE)
  }
    
  else if (files_cnt > 1) {
    rmarkdown::draft(file_name, template = "enr_report", package = "ENRanalytics", edit = FALSE)
    report_show(subdir, file, paste0(file, '.Rmd'))
  }
  
}
AMUFacultyOfEnglish/ENRanalytics documentation built on May 5, 2019, 11:36 a.m.