R/include_function.R

Defines functions include

Documented in include

#' Include: a relative source() function for R
#' 
#' Works when your R script is executable.
#' @param pathToSource full path to r script to source
#' @keywords source relative
#' @export

include <- function(pathToSource)
{
  argv <- commandArgs(trailingOnly = FALSE)
  file.arg.name <- "--file="
  script.name <- sub(file.arg.name, "", argv[grep(file.arg.name, argv)])
  script.basename <- dirname(script.name)
  if (length(script.basename) == 0)
    source(pathToSource)
  else
    source(paste(sep="/", script.basename, pathToSource))
}
e9group/include documentation built on May 29, 2017, 6:25 a.m.