R/script_paths.R

Defines functions script_paths

Documented in script_paths

#' Function to return a script's file name and directory from within itself. 
#'
#' \code{script_paths} is most useful when calling a script as a programme. 
#' 
#' @author Stuart K. Grange
#' 
#' @return Named list with two elements. 
#'
#' @export
script_paths <- function() {
  
  # Get script's file name
  if (!interactive()) {
    file <- scriptName::current_filename()
  } else {
    file <- rstudioapi::getActiveDocumentContext()$path
  }
  
  # Build a list return
  list(
    file = file,
    directory = fs::path_dir(file)
  )
  
}
skgrange/threadr documentation built on May 11, 2024, 12:16 p.m.