[Distr-commits] r1218 - branches/distr-2.8/pkg/utils pkg/utils
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 25 13:32:49 CEST 2018
Author: ruckdeschel
Date: 2018-07-25 13:32:49 +0200 (Wed, 25 Jul 2018)
New Revision: 1218
Modified:
branches/distr-2.8/pkg/utils/copyToBranch.R
branches/distr-2.8/pkg/utils/finde.R
pkg/utils/copyToBranch.R
pkg/utils/finde.R
Log:
utils: yet another enhancement for finde and ersetze:
+ no more warnings due to missing EOL
+ a unified interface for finde and ersetze,
+ argument restrictFilepattern
+ code in if(FALSE){} to source either trunk or devel version of finde.R
+ examples in if(FALSE){} blocks
-- entered a warning not to use copyToBranch.R any longer.
Modified: branches/distr-2.8/pkg/utils/copyToBranch.R
===================================================================
--- branches/distr-2.8/pkg/utils/copyToBranch.R 2018-07-25 10:31:36 UTC (rev 1217)
+++ branches/distr-2.8/pkg/utils/copyToBranch.R 2018-07-25 11:32:49 UTC (rev 1218)
@@ -25,3 +25,7 @@
copyToBranch(FILE="^pkg/utils/c.*",fromDir="C:/rtest/distr",
toDir="C:/rtest/distr/branches/distr-2.1",rec=TRUE)
+
+## should no longer be used:
+## use svn branch instead for a new branch
+## use svn merge to integrate a devel branch back into trunk
Modified: branches/distr-2.8/pkg/utils/finde.R
===================================================================
--- branches/distr-2.8/pkg/utils/finde.R 2018-07-25 10:31:36 UTC (rev 1217)
+++ branches/distr-2.8/pkg/utils/finde.R 2018-07-25 11:32:49 UTC (rev 1218)
@@ -1,44 +1,32 @@
-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){
- setwd(dir0)
- cat("\n")
- findL <- function(y){
- zz <- readLines(y)
- lgr <- grep(x,zz)
- if(length(lgr>0)){
- if(rec)
- cat(paste(dir0,"/",y,sep="")," :: ",paste(lgr),"\n")
- else cat(y," :: ",paste(lgr),"\n")
- }
- invisible()
- }
- 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)
+if(FALSE) {
+ ## use this to source this file / have finde() and ersetze() available
+
+ ## change svncheckout suitably...
+ svncheckout <- file.path("C:/rtest/distr")
+ trunk <- FALSE
+ ## if the version from devel
+ branches <- dir(file.path(svncheckout,"branches"))
+ branches <- grep("distr-",branches,value=TRUE)
+ branches <- branches[!grepl("\\.[[:alpha:]]+",branches)]
+ thisbranch <- max(branches)
+ thisdir <- file.path(svncheckout,"branches", thisbranch)
+ print(thisdir)
+ ## or in trunk
+ if(trunk) thisdir <- ""
+ print(file.path(thisdir,"pkg/utils/finde.R"))
+ source(file.path(thisdir,"pkg/utils/finde.R"))
}
+#
+
+finde <- function(x = "nchar", dir = "C:/rtest/distr/pkg/distr/R",
+ ext = "R", restrictFilepattern = "", excludeFilepattern = "",
+ excludeext = "", withEmpty = FALSE, rec = FALSE){
+ ersetze(x0=x, dir=dir, ext=ext, restrictFilepattern =restrictFilepattern,
+ excludeFilepattern = excludeFilepattern, excludeext =excludeext,
+ withEmpty = withEmpty, rec = rec, withoverwrite = FALSE)
+}
+
+if(FALSE){
finde(x="q\\(", dir ="C:/rtest/distr/branches/distr-2.7/pkg/", rec=TRUE)
finde(x="http\\:/", dir ="C:/rtest/distr/branches/distr-2.7/pkg/distr/", rec=TRUE)
#finde(x="Wow6432Node", dir ="C:/R/devel/src/gnuwin32", rec=TRUE, ext="")
@@ -51,20 +39,34 @@
finde(x=".makeQNew", dir ="C:/rtest/distr/pkg/distr/R")
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", excludeFilepattern="", excludeext="", rec = FALSE, withEmpty=FALSE, withoverwrite = FALSE){
+selectfiles <- function(pat,DIR, negate=FALSE){
+ if(! ((length(pat)==0)||((length(pat)==1)&&(all(pat==""))))){
+ patL <- sapply(pat, function(ext1) grepl(ext1, DIR))
+ if(!is.null(dim(patL))) patL <- apply(patL, 1, any)
+ if(negate) patL <- !patL
+ DIR <- DIR[patL]
+ }
+ return(DIR)
+}
+
+ersetze <- function(x0 = "nchar", x1 = "nchar", dir = "C:/rtest/distr/pkg/distr/R",
+ ext = "R", restrictFilepattern = "", excludeFilepattern = "",
+ excludeext = "", rec = FALSE, withEmpty = FALSE,
+ withoverwrite = FALSE){
ow <- getwd()
on.exit(setwd(ow))
infind <- function(dir0){
setwd(dir0)
cat("\n")
findL <- function(y){
- zz <- readLines(y)
+ zz <- readLines(y, warn = FALSE)
lgr <- grep(x0,zz)
if(length(lgr>0)){
if(withoverwrite) writeLines(gsub(x0,x1,zz),y)
if(rec)
- cat(paste(dir0,"/",y,sep="")," :: ",paste(lgr),"\n")
+ cat(file.path(dir0,y)," :: ",paste(lgr),"\n")
else cat(y," :: ",paste(lgr),"\n")
}
invisible()
@@ -80,22 +82,17 @@
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]
- }
+ DIR <- selectfiles(excludeext,DIR, negate=TRUE)
+ DIR <- selectfiles(restrictFilepattern,DIR, negate=FALSE)
+ DIR <- selectfiles(excludeFilepattern,DIR, negate=TRUE)
s <- lapply(DIR,findL)
}
infind(dir)
}
-ersetze(x0="https://distr.r-forge.r-project.org/",x1="http://distr.r-forge.r-project.org/", dir ="C:/rtest/distr/branches/distr-2.7/pkg", rec=TRUE,ext="Rd")
+if(FALSE){
+ersetze(x0="https://distr.r-forge.r-project.org/",x1="http://distr.r-forge.r-project.org/", dir ="C:/rtest/distr/branches/distr-2.7/pkg", rec=TRUE,ext="Rd")
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="@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/utils/copyToBranch.R
===================================================================
--- pkg/utils/copyToBranch.R 2018-07-25 10:31:36 UTC (rev 1217)
+++ pkg/utils/copyToBranch.R 2018-07-25 11:32:49 UTC (rev 1218)
@@ -25,3 +25,7 @@
copyToBranch(FILE="^pkg/utils/c.*",fromDir="C:/rtest/distr",
toDir="C:/rtest/distr/branches/distr-2.1",rec=TRUE)
+
+## should no longer be used:
+## use svn branch instead for a new branch
+## use svn merge to integrate a devel branch back into trunk
Modified: pkg/utils/finde.R
===================================================================
--- pkg/utils/finde.R 2018-07-25 10:31:36 UTC (rev 1217)
+++ pkg/utils/finde.R 2018-07-25 11:32:49 UTC (rev 1218)
@@ -1,44 +1,32 @@
-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){
- setwd(dir0)
- cat("\n")
- findL <- function(y){
- zz <- readLines(y)
- lgr <- grep(x,zz)
- if(length(lgr>0)){
- if(rec)
- cat(paste(dir0,"/",y,sep="")," :: ",paste(lgr),"\n")
- else cat(y," :: ",paste(lgr),"\n")
- }
- invisible()
- }
- 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)
+if(FALSE) {
+ ## use this to source this file / have finde() and ersetze() available
+
+ ## change svncheckout suitably...
+ svncheckout <- file.path("C:/rtest/distr")
+ trunk <- FALSE
+ ## if the version from devel
+ branches <- dir(file.path(svncheckout,"branches"))
+ branches <- grep("distr-",branches,value=TRUE)
+ branches <- branches[!grepl("\\.[[:alpha:]]+",branches)]
+ thisbranch <- max(branches)
+ thisdir <- file.path(svncheckout,"branches", thisbranch)
+ print(thisdir)
+ ## or in trunk
+ if(trunk) thisdir <- ""
+ print(file.path(thisdir,"pkg/utils/finde.R"))
+ source(file.path(thisdir,"pkg/utils/finde.R"))
}
+#
+
+finde <- function(x = "nchar", dir = "C:/rtest/distr/pkg/distr/R",
+ ext = "R", restrictFilepattern = "", excludeFilepattern = "",
+ excludeext = "", withEmpty = FALSE, rec = FALSE){
+ ersetze(x0=x, dir=dir, ext=ext, restrictFilepattern =restrictFilepattern,
+ excludeFilepattern = excludeFilepattern, excludeext =excludeext,
+ withEmpty = withEmpty, rec = rec, withoverwrite = FALSE)
+}
+
+if(FALSE){
finde(x="q\\(", dir ="C:/rtest/distr/branches/distr-2.7/pkg/", rec=TRUE)
finde(x="http\\:/", dir ="C:/rtest/distr/branches/distr-2.7/pkg/distr/", rec=TRUE)
#finde(x="Wow6432Node", dir ="C:/R/devel/src/gnuwin32", rec=TRUE, ext="")
@@ -51,20 +39,34 @@
finde(x=".makeQNew", dir ="C:/rtest/distr/pkg/distr/R")
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", excludeFilepattern="", excludeext="", rec = FALSE, withEmpty=FALSE, withoverwrite = FALSE){
+selectfiles <- function(pat,DIR, negate=FALSE){
+ if(! ((length(pat)==0)||((length(pat)==1)&&(all(pat==""))))){
+ patL <- sapply(pat, function(ext1) grepl(ext1, DIR))
+ if(!is.null(dim(patL))) patL <- apply(patL, 1, any)
+ if(negate) patL <- !patL
+ DIR <- DIR[patL]
+ }
+ return(DIR)
+}
+
+ersetze <- function(x0 = "nchar", x1 = "nchar", dir = "C:/rtest/distr/pkg/distr/R",
+ ext = "R", restrictFilepattern = "", excludeFilepattern = "",
+ excludeext = "", rec = FALSE, withEmpty = FALSE,
+ withoverwrite = FALSE){
ow <- getwd()
on.exit(setwd(ow))
infind <- function(dir0){
setwd(dir0)
cat("\n")
findL <- function(y){
- zz <- readLines(y)
+ zz <- readLines(y, warn = FALSE)
lgr <- grep(x0,zz)
if(length(lgr>0)){
if(withoverwrite) writeLines(gsub(x0,x1,zz),y)
if(rec)
- cat(paste(dir0,"/",y,sep="")," :: ",paste(lgr),"\n")
+ cat(file.path(dir0,y)," :: ",paste(lgr),"\n")
else cat(y," :: ",paste(lgr),"\n")
}
invisible()
@@ -80,22 +82,17 @@
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]
- }
+ DIR <- selectfiles(excludeext,DIR, negate=TRUE)
+ DIR <- selectfiles(restrictFilepattern,DIR, negate=FALSE)
+ DIR <- selectfiles(excludeFilepattern,DIR, negate=TRUE)
s <- lapply(DIR,findL)
}
infind(dir)
}
-ersetze(x0="https://distr.r-forge.r-project.org/",x1="http://distr.r-forge.r-project.org/", dir ="C:/rtest/distr/branches/distr-2.7/pkg", rec=TRUE,ext="Rd")
+if(FALSE){
+ersetze(x0="https://distr.r-forge.r-project.org/",x1="http://distr.r-forge.r-project.org/", dir ="C:/rtest/distr/branches/distr-2.7/pkg", rec=TRUE,ext="Rd")
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="@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