[Distr-commits] r1217 - branches/distr-2.8/pkg/distrEx/man branches/distr-2.8/pkg/utils pkg/distrEx/man pkg/utils

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 25 12:31:36 CEST 2018


Author: ruckdeschel
Date: 2018-07-25 12:31:36 +0200 (Wed, 25 Jul 2018)
New Revision: 1217

Modified:
   branches/distr-2.8/pkg/distrEx/man/0distrEx-package.Rd
   branches/distr-2.8/pkg/utils/finde.R
   pkg/distrEx/man/0distrEx-package.Rd
   pkg/utils/finde.R
Log:
[utils] enhanced "finde" and "ersetze" :
+ they can match several file extensions, including none
+ ersetze now only overwrites a file when it matches the pattern to be replaced (within the file selection)
+ several file extensions can be excluded
+ several filename patterns can be excluded, 
+ ersetze by default does not replace anything (for a first "cold try")
---------------------------------------
found & removed a no longer valid acknowledgement for Nataliya (in distrEx central man page for actuar::pareto1, which has been moved to RobExtremes)

Modified: branches/distr-2.8/pkg/distrEx/man/0distrEx-package.Rd
===================================================================
--- branches/distr-2.8/pkg/distrEx/man/0distrEx-package.Rd	2018-07-24 23:49:05 UTC (rev 1216)
+++ branches/distr-2.8/pkg/distrEx/man/0distrEx-package.Rd	2018-07-25 10:31:36 UTC (rev 1217)
@@ -167,8 +167,6 @@
 \section{Acknowledgement}{
 G. Jay Kerns, \email{gkerns at ysu.edu}, has provided a major contribution,
 in particular the functionals \code{skewness} and \code{kurtosis} are due to him.
-Natalyia Horbenko, \email{natalyia.horbenko at itwm.fraunhofer.de} has ported
-the \pkg{actuar} code for the Pareto distribution to this setup. 
 }
 
 \note{

Modified: branches/distr-2.8/pkg/utils/finde.R
===================================================================
--- branches/distr-2.8/pkg/utils/finde.R	2018-07-24 23:49:05 UTC (rev 1216)
+++ branches/distr-2.8/pkg/utils/finde.R	2018-07-25 10:31:36 UTC (rev 1217)
@@ -1,4 +1,4 @@
-finde <- function(x = "nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", rec = FALSE){
+finde <- function(x = "nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", excludeFilepattern="", excludeext="", withEmpty=FALSE, rec = FALSE){
   ow <- getwd()
   on.exit(setwd(ow))
   infind <- function(dir0){
@@ -14,8 +14,27 @@
        }
        invisible()
     }
-  ext0 <- if(ext=="") "" else paste("\\.", ext, sep="")
-  DIR <- grep(ext0, dir(, rec = rec), value=TRUE)
+  DIR <- dir(rec=rec)
+  if(! ((ext=="")&&(withEmpty))){
+     ext0 <- sapply(ext, function(ext1) if(ext=="") "" else paste("\\.", ext, sep=""))
+     extL <- sapply(ext0, function(ers) grepl(ers,DIR))
+     if(withEmpty){
+        emptyL <- !grepl("\\.", DIR)
+        extL <- cbind(extL,emptyL)
+     }
+     if(!is.null(dim(extL))) extL <- apply(extL, 1, any)
+     DIR <- DIR[extL]
+  }
+  if(! ((length(excludeext)==0)||((length(excludeext)==1)&&(all(excludeext==""))))){
+     excludeextL <- sapply(excludeext, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludeextL))) excludeextL <- apply(excludeextL, 1, any)
+     DIR <- DIR[!excludeextL]
+  }
+  if(! ((length(excludeFilepattern)==0)||((length(excludeFilepattern)==1)&&(all(excludeFilepattern==""))))){
+     excludepatternL <- sapply(excludeFilepattern, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludepatternL))) excludepatternL <- apply(excludepatternL, 1, any)
+     DIR <- DIR[!excludepatternL]
+  }
   s <- lapply(DIR,findL)
   }
 infind(dir)   
@@ -33,7 +52,7 @@
 finde(x="http://distr\\.r-forge\\.r-project\\.org/distr\\.pdf", dir ="C:/rtest/distr/", rec=TRUE)
 finde(x="cniper.+\\(", dir ="C:/rtest/robast/branches/robast-0.9/pkg", rec=TRUE)
 
-ersetze <- function(x0 = "nchar", x1="nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", rec = FALSE, withEmpty=FALSE){
+ersetze <- function(x0 = "nchar", x1="nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", excludeFilepattern="", excludeext="", rec = FALSE, withEmpty=FALSE, withoverwrite = FALSE){
   ow <- getwd()
   on.exit(setwd(ow))
   infind <- function(dir0){
@@ -42,17 +61,35 @@
     findL <- function(y){
        zz <- readLines(y)
        lgr <- grep(x0,zz)
-       writeLines(gsub(x0,x1,zz),y)
        if(length(lgr>0)){
+          if(withoverwrite) writeLines(gsub(x0,x1,zz),y)
           if(rec)
              cat(paste(dir0,"/",y,sep="")," :: ",paste(lgr),"\n")
           else cat(y," :: ",paste(lgr),"\n")
        }
        invisible()
     }
-  ext0 <- if(ext=="") "" else paste("\\.", ext, sep="")
-  DIR <- dir(, rec = rec)
-  if(!withEmpty) DIR <- grep(ext0, DIR, value=TRUE)
+  DIR <- dir(rec=rec)
+  if(! ((ext=="")&&(withEmpty))){
+     ext0 <- sapply(ext, function(ext1) if(ext=="") "" else paste("\\.", ext, sep=""))
+     extL <- sapply(ext0, function(ers) grepl(ers,DIR))
+     if(withEmpty){
+        emptyL <- !grepl("\\.", DIR)
+        extL <- cbind(extL,emptyL)
+     }
+     if(!is.null(dim(extL))) extL <- apply(extL, 1, any)
+     DIR <- DIR[extL]
+  }
+  if(! ((length(excludeext)==0)||((length(excludeext)==1)&&(all(excludeext==""))))){
+     excludeextL <- sapply(excludeext, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludeextL))) excludeextL <- apply(excludeextL, 1, any)
+     DIR <- DIR[!excludeextL]
+  }
+  if(! ((length(excludeFilepattern)==0)||((length(excludeFilepattern)==1)&&(all(excludeFilepattern==""))))){
+     excludepatternL <- sapply(excludeFilepattern, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludepatternL))) excludepatternL <- apply(excludepatternL, 1, any)
+     DIR <- DIR[!excludepatternL]
+  }
   s <- lapply(DIR,findL)
   }
 infind(dir)
@@ -61,4 +98,4 @@
 
 ersetze(x0="href=\"distr.pdf\"",x1="href=\"http://cran.r-project.org/web/packages/distrDoc/vignettes/distr.pdf\"", dir ="C:/rtest/distr/www", rec=TRUE,ext="html")
 ersetze(x0="peter.ruckdeschel at uni-bayreuth.de",x1="peter.ruckdeschel at uni-oldenburg.de", dir ="C:/rtest/distr/www", rec=TRUE, ext="html")
-ersetze(x0="peter.ruckdeschel at itwm.fraunhofer.de", x1="peter.ruckdeschel at uni-oldenburg.de", dir ="C:/rtest/robast/branches/robast-1.1", rec=TRUE, ext="Rd")
+ersetze(x0="@itwm.fraunhofer.de", x1="@uni-oldenburg.de", dir ="C:/rtest/robast/branches/robast-1.1", rec=TRUE, withEmpty=TRUE, ext="", excludeext=c("pdf","Rout\\.save","tar\\.gz", excludeFilepattern="Rcheck"))

Modified: pkg/distrEx/man/0distrEx-package.Rd
===================================================================
--- pkg/distrEx/man/0distrEx-package.Rd	2018-07-24 23:49:05 UTC (rev 1216)
+++ pkg/distrEx/man/0distrEx-package.Rd	2018-07-25 10:31:36 UTC (rev 1217)
@@ -167,8 +167,6 @@
 \section{Acknowledgement}{
 G. Jay Kerns, \email{gkerns at ysu.edu}, has provided a major contribution,
 in particular the functionals \code{skewness} and \code{kurtosis} are due to him.
-Natalyia Horbenko, \email{natalyia.horbenko at itwm.fraunhofer.de} has ported
-the \pkg{actuar} code for the Pareto distribution to this setup. 
 }
 
 \note{

Modified: pkg/utils/finde.R
===================================================================
--- pkg/utils/finde.R	2018-07-24 23:49:05 UTC (rev 1216)
+++ pkg/utils/finde.R	2018-07-25 10:31:36 UTC (rev 1217)
@@ -1,4 +1,4 @@
-finde <- function(x = "nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", rec = FALSE){
+finde <- function(x = "nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", excludeFilepattern="", excludeext="", withEmpty=FALSE, rec = FALSE){
   ow <- getwd()
   on.exit(setwd(ow))
   infind <- function(dir0){
@@ -14,8 +14,27 @@
        }
        invisible()
     }
-  ext0 <- if(ext=="") "" else paste("\\.", ext, sep="")
-  DIR <- grep(ext0, dir(, rec = rec), value=TRUE)
+  DIR <- dir(rec=rec)
+  if(! ((ext=="")&&(withEmpty))){
+     ext0 <- sapply(ext, function(ext1) if(ext=="") "" else paste("\\.", ext, sep=""))
+     extL <- sapply(ext0, function(ers) grepl(ers,DIR))
+     if(withEmpty){
+        emptyL <- !grepl("\\.", DIR)
+        extL <- cbind(extL,emptyL)
+     }
+     if(!is.null(dim(extL))) extL <- apply(extL, 1, any)
+     DIR <- DIR[extL]
+  }
+  if(! ((length(excludeext)==0)||((length(excludeext)==1)&&(all(excludeext==""))))){
+     excludeextL <- sapply(excludeext, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludeextL))) excludeextL <- apply(excludeextL, 1, any)
+     DIR <- DIR[!excludeextL]
+  }
+  if(! ((length(excludeFilepattern)==0)||((length(excludeFilepattern)==1)&&(all(excludeFilepattern==""))))){
+     excludepatternL <- sapply(excludeFilepattern, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludepatternL))) excludepatternL <- apply(excludepatternL, 1, any)
+     DIR <- DIR[!excludepatternL]
+  }
   s <- lapply(DIR,findL)
   }
 infind(dir)   
@@ -33,7 +52,7 @@
 finde(x="http://distr\\.r-forge\\.r-project\\.org/distr\\.pdf", dir ="C:/rtest/distr/", rec=TRUE)
 finde(x="cniper.+\\(", dir ="C:/rtest/robast/branches/robast-0.9/pkg", rec=TRUE)
 
-ersetze <- function(x0 = "nchar", x1="nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", rec = FALSE, withEmpty=FALSE){
+ersetze <- function(x0 = "nchar", x1="nchar", dir="C:/rtest/distr/pkg/distr/R", ext = "R", excludeFilepattern="", excludeext="", rec = FALSE, withEmpty=FALSE, withoverwrite = FALSE){
   ow <- getwd()
   on.exit(setwd(ow))
   infind <- function(dir0){
@@ -42,17 +61,35 @@
     findL <- function(y){
        zz <- readLines(y)
        lgr <- grep(x0,zz)
-       writeLines(gsub(x0,x1,zz),y)
        if(length(lgr>0)){
+          if(withoverwrite) writeLines(gsub(x0,x1,zz),y)
           if(rec)
              cat(paste(dir0,"/",y,sep="")," :: ",paste(lgr),"\n")
           else cat(y," :: ",paste(lgr),"\n")
        }
        invisible()
     }
-  ext0 <- if(ext=="") "" else paste("\\.", ext, sep="")
-  DIR <- dir(, rec = rec)
-  if(!withEmpty) DIR <- grep(ext0, DIR, value=TRUE)
+  DIR <- dir(rec=rec)
+  if(! ((ext=="")&&(withEmpty))){
+     ext0 <- sapply(ext, function(ext1) if(ext=="") "" else paste("\\.", ext, sep=""))
+     extL <- sapply(ext0, function(ers) grepl(ers,DIR))
+     if(withEmpty){
+        emptyL <- !grepl("\\.", DIR)
+        extL <- cbind(extL,emptyL)
+     }
+     if(!is.null(dim(extL))) extL <- apply(extL, 1, any)
+     DIR <- DIR[extL]
+  }
+  if(! ((length(excludeext)==0)||((length(excludeext)==1)&&(all(excludeext==""))))){
+     excludeextL <- sapply(excludeext, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludeextL))) excludeextL <- apply(excludeextL, 1, any)
+     DIR <- DIR[!excludeextL]
+  }
+  if(! ((length(excludeFilepattern)==0)||((length(excludeFilepattern)==1)&&(all(excludeFilepattern==""))))){
+     excludepatternL <- sapply(excludeFilepattern, function(ext1) grepl(ext1, DIR))
+     if(!is.null(dim(excludepatternL))) excludepatternL <- apply(excludepatternL, 1, any)
+     DIR <- DIR[!excludepatternL]
+  }
   s <- lapply(DIR,findL)
   }
 infind(dir)
@@ -61,4 +98,4 @@
 
 ersetze(x0="href=\"distr.pdf\"",x1="href=\"http://cran.r-project.org/web/packages/distrDoc/vignettes/distr.pdf\"", dir ="C:/rtest/distr/www", rec=TRUE,ext="html")
 ersetze(x0="peter.ruckdeschel at uni-bayreuth.de",x1="peter.ruckdeschel at uni-oldenburg.de", dir ="C:/rtest/distr/www", rec=TRUE, ext="html")
-ersetze(x0="peter.ruckdeschel at itwm.fraunhofer.de", x1="peter.ruckdeschel at uni-oldenburg.de", dir ="C:/rtest/robast/branches/robast-1.1", rec=TRUE, ext="Rd")
+ersetze(x0="@itwm.fraunhofer.de", x1="@uni-oldenburg.de", dir ="C:/rtest/robast/branches/robast-1.1", rec=TRUE, withEmpty=TRUE, ext="", excludeext=c("pdf","Rout\\.save","tar\\.gz", excludeFilepattern="Rcheck"))



More information about the Distr-commits mailing list