R/top_dir.R

Defines functions top_dir

top_dir <- function(path,
                    n=1,
                    invert=FALSE,
                    concat=TRUE){
    
    split <- grep("^$",strsplit(x = path, 
                                split = .Platform$file.sep)[[1]],
                  invert = TRUE, 
                  value = TRUE)
    if(isFALSE(invert)){
        split <- split[seq_len(n)]
    } else {
        split <- split[seq((length(split)-n+1),length(split))]
    }
    if(isTRUE(concat)){
        return(Reduce(file.path,split))
    } else {
        return(split)
    }
}
neurogenomics/PeakyFinders documentation built on Oct. 14, 2024, 3:09 p.m.