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 March 24, 2024, 4:28 p.m.