Learn R Programming

coexist (version 1.0)

convert.filenames: convert saved data sets' names in to a vector based on the order of numbers, which will be called by batch.read() function

Description

convert saved data sets' names in to a vector based on the order of numbers, which will be called by batch.read() function

Usage

convert.filenames(folder)

Arguments

folder
the folder that stored all the model outputs, not a detailed filename

Value

return a vector for each member is a path pointed to a filename (a model output), which can be called by batch.read() function

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.

See Also

read.data, batch.read, read.patchdata

Examples

Run this code
##---- 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 (folder) 
{
    files <- list.files(path = folder, full.names = TRUE)
    newf <- vector()
    fnum <- length(files)
    length(newf) <- fnum
    dataorder <- rep(0, 1, fnum)
    for (i in 1:fnum) {
        pos.end <- unlist(gregexpr("00yh", files[i]))[1] - 1
        pos.start <- unlist(gregexpr(paste(folder, "/out", sep = ""), 
            files[i]))[1] + 15
        dataorder[i] <- as.numeric(substr(files[i], pos.start, 
            pos.end))
    }
    for (i in 1:fnum) {
        newf[dataorder[i]] <- files[i]
    }
    newf <- newf[!is.na(newf)]
    return(newf)
  }

Run the code above in your browser using DataLab