R/setpwd.R

Defines functions setpwd

Documented in setpwd

#' setpwd
#'
#' set current working directory to the RScript path
#' setpwd ensure when the script is envoke by RScript, 
#' the working directory should be where the script locates
#'
#' set pwd for Rscript
#' @return current_pwd
#' @export
setpwd <- function() {

  pwd <- getwd()
  if (!interactive()) {
    CArgs <- commandArgs(trailingOnly=FALSE)
    setwd(dirname(sub("^--file=", "", CArgs[grepl("^--file=", CArgs)])))
  }
  invisible(pwd)

}
obarisk/rconf documentation built on May 3, 2019, 9:01 p.m.