Creating an extended file path concatenator function

This commit is contained in:
hollorol 2017-09-02 00:55:30 +02:00
parent ea8fac69e4
commit 0ecb54aaf7
4 changed files with 60 additions and 35 deletions

View File

@ -3,6 +3,7 @@
export(calibMuso)
export(cleanupMuso)
export(corrigMuso)
export(file.path2)
export(getyearlycum)
export(getyearlymax)
export(musoDate)

View File

@ -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(

View File

@ -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))
}
}

View File

@ -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
}