# user and home setup ----
# Current user's name on the system
# If regular desktop R session, use Sys.getenv("USERNAME")
# If on RStudio server, use Sys.getenv("RSTUDIO_USER_IDENTITY")
user <- ifelse(Sys.getenv("USERNAME") == "",
               Sys.getenv("RSTUDIO_USER_IDENTITY"),
               Sys.getenv("USERNAME"))
if(user == "grandin"){
  # Add specialized user code here
}

# system_() figures out which OS you are on and runs the proper function
home <- system_("echo $HOME", intern = TRUE)

if(home == ""){
  stop("`home` is an empty string. The `system(echo $HOME)` call failed ",
       "which means the $HOME variable in the OS is not set")
}
models_dir <- "/srv/hake/models"
test <- rmarkdown::metadata$output$`hake_beamer`$test %||% FALSE
if(test){
  # Necessary for `gotest()` testing
  devtools::load_all(paste0(home, "/github/pacific-hake/hake-assessment"))
}else{
  # For regular doc build
  devtools::load_all(here::here())
}

# This grabs the YAML `project_variables` from above
yaml_proj_vars <- rmarkdown::metadata$project_variables

# Don't modify anything in `opts_chunk$set()`. Modify the YAML
# `project_variables` above
knitr::opts_chunk$set(
  # `collapse` - If `TRUE`, source code and output will remain together in
  # one chunk (inseparable from each other in the document). Probably
  # doesn't apply for this document but remains in case any source code is
  # shown
  collapse = TRUE,
  # Don't show warnings, messages, or source code (respectively)
  # in the document
  warning = FALSE,
  message = FALSE,
  echo = FALSE,
  # Create the `knitr_cache_dir` and `knitr_figs_dir` directories for caching
  cache = TRUE,
  cache.path = yaml_proj_vars$knitr_cache_dir,
  # cache.lazy - if `FALSE`, load the models at the beginning all at once
  cache.lazy = FALSE,
  # Prevents invalidation of the cache when only comments are entered
  # in chunks
  cache.comments = FALSE,
  results = "hide",
  comment = "#>",
  dev = yaml_proj_vars$fig_filetype,
  dpi = yaml_proj_vars$dots_per_inch,
  fig.path = yaml_proj_vars$knitr_figures_dir,
  fig.align = "center",
  fig.pos = yaml_proj_vars$fig_pos,
  fig.height = yaml_proj_vars$fig_height,
  fig.width = yaml_proj_vars$fig_width,
  out.height = "\\textheight",
  out.width = "\\textwidth")

fig_dir <- file.path(getwd(), "knitr-figs")
if(!dir.exists(fig_dir)){
  dir.create(fig_dir)
}


pacific-hake/hake-assessment documentation built on July 21, 2024, 8:19 a.m.