forked from r-spatial/link2GI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitProj.R
executable file
·41 lines (35 loc) · 1.35 KB
/
initProj.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if ( !isGeneric("initProj") ) {
setGeneric("initProj", function(x, ...)
standardGeneric("initProj"))
}
#' initProj
#'@description Defines and creates (if necessary) all folders variables
#' set the SAGA path variables and other system variables
#' exports all variables to the global environment
#'
#'@param projRootDir project github root directory (your github name)
#'@param projFolders list of subfolders in project
#'
#'@export initProj
#'
initProj <- function(projRootDir=getwd(), projFolders=c("data/","result/","run/","log/")) {
# switch backslash to slash and expand path to full path
projRootDir <- gsub("\\\\", "/", path.expand(projRootDir))
# check tailing / and if not existing append
if (substr(projRootDir,nchar(projRootDir) - 1,nchar(projRootDir)) != "/") {
projRootDir <- paste0(projRootDir,"/")
}
# create directories if needed
for (folder in projFolders) {
if (!file.exists(file.path(projRootDir,folder))) {
dir.create(file.path(projRootDir,folder), recursive = TRUE)
name <- paste0("path_",substr(folder,1,nchar(folder) - 1))
value <- paste0(projRootDir,folder)
makGlobalVar(name, value)
} else {
name <- paste0("path_",substr(folder,1,nchar(folder) - 1))
value <- paste0(projRootDir,folder)
makGlobalVar(name, value)
}
}
}