Guest User

Untitled

a guest
Jul 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/usr/bin/env Rscript
  2. .script.folder <- function() {
  3. if (is.vector(commandArgs(0))) {
  4. args <- commandArgs(0)
  5. filearg <- Filter(function(arg) { (regexpr("^--file", arg) != -1) }, commandArgs(0) )[1]
  6. if (! is.na(filearg)) {
  7. scriptname <- gsub("^--file=", "", filearg)
  8. return(dirname(scriptname));
  9. }
  10. } else {
  11. getwd()
  12. }
  13. }
  14.  
  15. .is.project.root <- function(dir) {
  16. (dir == ".") || (dir == "/") || (file.access(paste(dir, ".git", sep="/")) == 0) || (file.access(paste(dir, ".projectroot", sep="/")) == 0)
  17. }
  18.  
  19. project.root <- function() {
  20. dir <- .script.folder()
  21. while ( ! .is.project.root(dir)) dir <- dirname(dir)
  22. dir
  23. }
Add Comment
Please, Sign In to add comment