filename.check: open,check and create a new folder if not existed

Description Usage Arguments Author(s) References Examples

View source: R/coexist.R

Description

an internal function; please note that the default folder used for the simulation (if you don't point it out clearly, the package will allocate a path as "c://outcome")

Usage

1

Arguments

path

local file path

return

if return=TRUE, it will return a checked new filename with adding the sign as "xxxx00yh0.xxxx.dat" format

Author(s)

Youhua Chen <yhchen@zoology.ubc.ca>

References

Chen YH (2012) coexist: an R package for performing species coexistence modeling and analysis under asymmetric dispersal and fluctuating source-sink dynamics. http://code.google.com/p/coexist.

Examples

 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
42
43
44
45
46
47
48
49
50
51
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (path = NULL, return = TRUE) 
{
    randnum <- runif(1)
    if (length(path) != 0) {
        pos <- unlist(gregexpr("/", path))
        dot <- unlist(gregexpr(".", path, fixed = T))
        dd <- unlist(gregexpr(":", path, fixed = T))
        special <- unlist(gregexpr("00yh", path))
        if (length(pos) >= 2 & dot[1] != -1 & dd[1] != -1 & special[1] != 
            -1) {
            folder <- substr(path, 1, pos[length(pos)] - 1)
            dir.create(folder, showWarnings = F)
            fname <- path
        }
        if (length(pos) >= 2 & dot[1] != -1 & dd[1] != -1 & special[1] == 
            -1) {
            folder <- substr(path, 1, pos[length(pos)] - 1)
            dir.create(folder, showWarnings = F)
            fname <- paste(substr(path, 1, dot[length(dot)] - 
                1), "00yh", substr(path, dot[length(dot)], nchar(path)), 
                sep = "")
        }
        if (dot[1] == -1 & dd[1] != -1 & special[1] == -1) {
            dir.create(path, showWarnings = F)
            fname <- paste(path, "/", randnum, "00yh", ".dat", 
                sep = "")
        }
        if (dot[1] == -1 & dd[1] == -1 & special[1] == -1) {
            path <- paste("c://", path, sep = "")
            dir.create(path, showWarnings = F)
            fname <- paste(path, "/", randnum, "00yh", ".dat", 
                sep = "")
        }
    }
    if (length(path) == 0) {
        if (length(folder) == 0) {
            folder = "c://outcome"
        }
        fname <- paste(folder, "/", randnum, "00yh", ".dat", 
            sep = "")
        dir.create(folder, showWarnings = F)
    }
    if (return == T) {
        return(fname)
    }
  }

coexist documentation built on May 2, 2019, 1:43 p.m.