From 0ecb54aaf7917abe952b207b7921adb8770421a0 Mon Sep 17 00:00:00 2001 From: hollorol Date: Sat, 2 Sep 2017 00:55:30 +0200 Subject: [PATCH] Creating an extended file path concatenator function --- RBBGCMuso/NAMESPACE | 1 + RBBGCMuso/R/cleanup.R | 51 +++++++++-------------------- RBBGCMuso/R/otherUsefullFunctions.R | 20 +++++++++++ RBBGCMuso/man/file.path2.Rd | 23 +++++++++++++ 4 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 RBBGCMuso/man/file.path2.Rd diff --git a/RBBGCMuso/NAMESPACE b/RBBGCMuso/NAMESPACE index c10acaf..0d4df57 100644 --- a/RBBGCMuso/NAMESPACE +++ b/RBBGCMuso/NAMESPACE @@ -3,6 +3,7 @@ export(calibMuso) export(cleanupMuso) export(corrigMuso) +export(file.path2) export(getyearlycum) export(getyearlymax) export(musoDate) diff --git a/RBBGCMuso/R/cleanup.R b/RBBGCMuso/R/cleanup.R index 05c88df..c566690 100644 --- a/RBBGCMuso/R/cleanup.R +++ b/RBBGCMuso/R/cleanup.R @@ -11,59 +11,40 @@ cleanupMuso <- function(location=NULL, simplicity=TRUE,deep=FALSE){ - areThereAnyFolders <- FALSE + + whereAmI <- getwd() if(!is.null(location)){ setwd(location) } if(deep){ - if(dir.exists("LOG")){ - setwd("LOG") + + + + if(dir.exists(paste(location,"/LOG",sep=""))){ file.remove( - grep("(out$)|(endpoint$)|(log$)", - list.files(), value = T)) - areThereAnyFolders <- TRUE + list.files("LOG/",pattern="(out$)|(endpoint$)|(log$)", full.names=TRUE) + ) } - - if(dir.exists("../ERROR")){ - setwd("../ERROR") - + if(dir.exists("ERROR")){ file.remove( - grep("(out$)|(endpoint$)|(log$)", - list.files(), value = T)) - areThereAnyFolders <- TRUE + list.files("ERROR/",pattern="(out$)|(endpoint$)|(log$)", full.names=TRUE)) } - - if(dir.exists("../EPCS")){ - setwd("../EPCS") - + if(dir.exists("EPCS")){ file.remove( - grep("(out$)|(endpoint$)|(log$)|(epc$)", - list.files(), value = T)) - areThereAnyFolder <- TRUE + list.files("EPCS/",pattern="(out$)|(endpoint$)|(log$)", full.names=TRUE)) } - if(dir.exists("../WRONGEPC")){ - setwd("../WRONGEPC") + if(dir.exists("WRONGEPC")){ file.remove( - grep("(out$)|(endpoint$)|(log$)|(epc$)", - list.files(), value = T)) - areThereAnyFolders <- TRUE + list.files("WRONGEPC/",pattern="(out$)|(endpoint$)|(log$)", full.names=TRUE)) } - if(areThereAnyFolders){ - setwd("..") - file.remove( - grep("(out$)|(endpoint$)|(log$)", - list.files(), value = T)) - } else { - file.remove( - grep("(out$)|(endpoint$)|(log$)", - list.files(), value = T))} - } + file.remove(list.files(pattern="(out$)|(endpoint$)|(log$)",full.names=TRUE))} + if(!simplicity){ file.remove( diff --git a/RBBGCMuso/R/otherUsefullFunctions.R b/RBBGCMuso/R/otherUsefullFunctions.R index ddbe61f..b15f8dc 100644 --- a/RBBGCMuso/R/otherUsefullFunctions.R +++ b/RBBGCMuso/R/otherUsefullFunctions.R @@ -113,3 +113,23 @@ corrigMuso <- function(settings, data){ } return(data) } + +#' file.path2 +#' +#' It is an extended file.path function, it can concatenate path where the first ends and the second begins with "/", so +#' there wont be two slash nearby eachother +#' @author Roland Hollos +#' @param str1 This is the first path string +#' @param str2 This is the second path string +#' @return A concatenated path +#' @export +#' @usage file.path2(str1, str2) + +file.path2<-function(str1, str2){ + str1<-file.path(dirname(str1),basename(str1)) + if(substring(str2,1,1)=="/"){ + return(paste(str1,str2,sep="")) + } else{ + return(file.path(str1,str2)) + } +} diff --git a/RBBGCMuso/man/file.path2.Rd b/RBBGCMuso/man/file.path2.Rd new file mode 100644 index 0000000..f243191 --- /dev/null +++ b/RBBGCMuso/man/file.path2.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/otherUsefullFunctions.R +\name{file.path2} +\alias{file.path2} +\title{file.path2} +\usage{ +file.path2(str1, str2) +} +\arguments{ +\item{str1}{This is the first path string} + +\item{str2}{This is the second path string} +} +\value{ +A concatenated path +} +\description{ +It is an extended file.path function, it can concatenate path where the first ends and the second begins with "/", so +there wont be two slash nearby eachother +} +\author{ +Roland Hollos +}