R/source_wd.R

Defines functions source_wd

Documented in source_wd

#' Configure the working directory
#'
#' Ensure the project root is set up correctly and create a global variable wd to represent the project root as working directory.
#'
#' @param this_file The name of the script calling the function. This uses here::i_am to set the project root correctly.
#'
#' @return
#' @export
#'
source_wd = function(this_file) {
  source_packages("here",
                  show_loaded_packages = F,
                  show_package_processes = F)

  # suppressMessages(here::i_am(file.path("..", this_file) ))
  suppressMessages(here::i_am(this_file ))

  cat("Setting working directory to", here(),"\n")
  cat("Assigning working directory to the global variable 'wd'")
  # here() %T>% assign("wd", ., envir = .GlobalEnv)
  assign("wd", here(), envir = .GlobalEnv)
  setwd(wd)
}
brendan-newlon/sourceR documentation built on Jan. 28, 2022, 10:14 a.m.