Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env Rscript
- .script.folder <- function() {
- if (is.vector(commandArgs(0))) {
- args <- commandArgs(0)
- filearg <- Filter(function(arg) { (regexpr("^--file", arg) != -1) }, commandArgs(0) )[1]
- if (! is.na(filearg)) {
- scriptname <- gsub("^--file=", "", filearg)
- return(dirname(scriptname));
- }
- } else {
- getwd()
- }
- }
- .is.project.root <- function(dir) {
- (dir == ".") || (dir == "/") || (file.access(paste(dir, ".git", sep="/")) == 0) || (file.access(paste(dir, ".projectroot", sep="/")) == 0)
- }
- project.root <- function() {
- dir <- .script.folder()
- while ( ! .is.project.root(dir)) dir <- dirname(dir)
- dir
- }
Add Comment
Please, Sign In to add comment