knitr::opts_chunk$set(
  comment = "##",
  tidy = FALSE, #`styler` to use styler:style_text() to reformat code
  tidy.opts = list(blank = FALSE, width.cutoff = 60),
  echo = TRUE,
  eval = TRUE,
  cache = FALSE,
  child = NULL, #file/s to knit and then include,
  collapse = FALSE, #collapse all output into a single block,
  error = FALSE, #display error messages in doc. FALSE stops render when error is thrown
  fig.align = "center", #left, right, center, or default
  fig.width = 7, #inches
  fig.height = 7, #inches
  fig.asp=0.50, #adds whitespace around images
  include = TRUE, #include chunk?
  message = TRUE, #display code messages?
  warning = TRUE, #include warnings?
  results = "markup"
    # "asis": passthrough results
    # "hide": do not display results 
    # "hold": put all results below all code
)  

# If the session is interactive, the Rmd title is 
# checked against the filename and the parameterized value, which should be the same.
  if (interactive()) { 
    rmd_title_by_filename <- xfun::sans_ext(basename(rstudioapi::getSourceEditorContext()$path)) 
    rmd_title_by_params <- 
        sprintf("%s: %s", 
            gsub(pattern = "^'|'$", 
                 x = params$issue_key,
                 replacement = ""),
            params$report_title)
     if (rmd_title_by_filename != rmd_title_by_params) {
       stop("Filename does not match parameterized name")
     } else {
     rmd_title <- rmd_title_by_filename
     }

  } else {
  rmd_title <- 
    sprintf("%s: %s", 
            gsub(pattern = "^'|'$", 
                 x = params$issue_key,
                 replacement = ""),
            params$report_title)
  }

github_page  <- sprintf("%s/%s.html", params$github_page_path, rmd_title)
source_code  <- sprintf("%s/%s.Rmd", params$source_code_page_path, rmd_title)
issue_key    <- params$issue_key
report_title <- params$report_title
project_path <- path.expand(params$project_path)

Last Updated On: r Sys.time()

library(tidyverse)
library(easyBakeOven)

Parameters

params_display <- 
  c(params,
    rmd_title = rmd_title, 
    github_page = github_page, 
    source_code = source_code)
names(params_display) <- str_to_title(str_replace_all(names(params_display), "[_]{1}", " "))
print_list(params_display)
global_data_folder  <- file.path(project_path, "data", issue_key, report_title)
raw_folder          <- file.path(global_data_folder, "raw")
intermediate_folder <- file.path(global_data_folder, "intermediate")
final_folder        <- file.path(global_data_folder, "final")
outgoing_folder     <- file.path(global_data_folder, "outgoing") 


global_rmd_folder   <- file.path(project_path, "rmd", issue_key)
child_rmd_folder    <- file.path(global_rmd_folder, report_title)

global_img_folder   <- file.path(project_path, "img", issue_key)
img_folder          <- file.path(global_img_folder, report_title)
cache_folder        <- file.path(project_path, "cache", issue_key, report_title, "/")

sapply(c(global_data_folder,
         raw_folder,
         intermediate_folder,
         final_folder,
         outgoing_folder,
         global_rmd_folder,
         child_rmd_folder,
         global_img_folder,
         img_folder,
         cache_folder),
       create_path)

knitr::opts_chunk$set(
  cache.path = cache_folder
)  
data(mtcars)
DT::datatable(mtcars)


patelm9/broca documentation built on Dec. 28, 2021, 5:31 a.m.