[Distr-commits] r1325 - pkg/utils

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 13 19:58:03 CET 2019


Author: ruckdeschel
Date: 2019-03-13 19:58:03 +0100 (Wed, 13 Mar 2019)
New Revision: 1325

Modified:
   pkg/utils/DESCRIPTIONutils.R
   pkg/utils/DESCRIPTIONutilsExamples.R
   pkg/utils/README-R-utils
Log:
[DESCRIPTIONutils] changeDescription now has an additional argument ReqDistrPkgVersion 
##         ReqDistrPkgVersion = NA, if not NA a (named) list of length(pkgs) with an entry
##                       for each package; for each package the entry is a named character 
##                       vector with the required versions of packages of form 
##                       "<pkg>"="<pkg>(>=..)"
In addition, the written DCF file now has fixed width 95 and indentation 12, and the updated 
.Rd File may have multiline DESCRIPTION entries and required R/package versions also can
be set in these multiline entries  


Modified: pkg/utils/DESCRIPTIONutils.R
===================================================================
--- pkg/utils/DESCRIPTIONutils.R	2019-03-12 09:22:38 UTC (rev 1324)
+++ pkg/utils/DESCRIPTIONutils.R	2019-03-13 18:58:03 UTC (rev 1325)
@@ -29,24 +29,99 @@
   if(length(PFfileI)){
   PFfile <- file.path(package, "man", PFfileI)
   PF     <-  readLines(con = PFfile)
+  PF.0 <- skipLineFeeds(PF)
+  nms.DFF <- colnames(DFF)
   replaceField <- function(field, dfile){
-     liS <- paste("(",field,":[[:blank:]]+\\\\tab).+(\\\\cr.*)",sep="")
-     reS <- paste("\\1",DFF[1,field],"\\2")
-     df0 <- gsub(liS, reS,dfile)
+     liS <- paste("(",field,":[[:blank:]]+\\\\tab).+(\\\\cr[^\n\r]*)",sep="")
+     repS <- paste(DFF[1,field],collapse="")
+     reS <- paste("\\1",sub("[\r\n]","",repS),"\\2")
+     dfile0 <- skipLineFeeds(dfile, FALSE)
+     df1 <- sub(liS, reS,dfile0)
+     df0 <- unlist(sapply(df1,Linebreak80))
+     names(df0) <- NULL
      return(df0)}
-  PFc    <-  PF
-  s <- sapply(c("Package","Version","Date","Depends","License","VCS/SVNRevision"),
-              function(x){ PFca <- replaceField(field=x,dfile=PFc)
-                           PFc <<- PFca
-                           return(NA)})
-  writeLines(PFc, con = PFfile)
+  PFc    <-  PF.0
+  s <- sapply(c("Package","Version","Date","Depends","Suggests",
+                "Imports", "License", "Enhances", "VCS/SVNRevision"),
+              function(x){ if(x %in% nms.DFF){
+                              PFca <- replaceField(field=x,dfile=PFc)
+                              PFc <<- PFca
+                           }
+                           return(invisible(NA))})
+#  print(PFc)
+  PFc.1 <- revertLineSkips(PFc)
+  names(PFc.1) <- NULL
+  writeLines(PFc.1, con = PFfile)
   return(invisible())
   }}
 }
+## in updatePackageHelp, we need to wrap multiline input of DESCRIPTION
+## to this end use two helper functions skipLineFeeds() and revertLineSkips()
 
+skipLineFeeds <- function(x, withMark=TRUE){
+   ## binds together all lines until a \cr or end of file is reached;
+   ## separate the pasted lines by ";;;"
+   if(any(is.na(x)|is.null(x))) return(character(0))
+   j <- 0; i <- 0; x.l<-length(x)
+   if(x.l==0)return(character(0))
+   x.0 <- character(x.l)
+   aktblock <- ""
+   mark <- if(withMark) ";;;" else " "
+   while(i<x.l){
+     i <- i + 1
+     if(aktblock!="")
+          aktblock <- paste(aktblock,mark,x[i],sep="")
+     else aktblock <- x[i]
+     if(grepl("\\\\cr",aktblock)){
+        j <- j + 1
+        x.0[j] <- aktblock
+        aktblock <- ""
+     }
+   }
+   return(c(x.0[1:j],aktblock))
+}
 
+revertLineSkips <- function(x){
+   ## undoes the binding
+    return(c(unlist(strsplit(x,";;;"))))
+}
+
+## we also have to introduce linebreaks at 80
+## getKommaPos80 finds the last comma before the 80th sign
+getKommaPos80 <- function(x){
+  nx <- nchar(x)
+  npos <- numeric(nx)
+  ind <- 1:nx
+  for(i in 1:nx) npos[i] <- substr(x,i,i)==","
+  if(sum(npos)==0) return(NA)
+  lc <- rev(ind[ind<=80 & npos])
+  if(length(lc)==0) return(NA)
+  return(lc[1])
+}
+## getKommaPos80 produces lines of length atmost 80
+Linebreak80 <- function(x){
+  if(length(x)==0) return(character(0))
+  nx <- nchar(x)
+  if(nx <= 80) return(x)
+  Komma <- getKommaPos80(x)
+  if(is.na(Komma)) return(x)
+  start <- substr(x,1,Komma)
+  rest <- gsub("^[[:blank:]]*","",substr(x,(Komma+1),nx))
+  if(nchar(rest)==0) return(start)
+  rest0 <- paste("    ", rest, sep="")
+  if(nchar(rest0<=80)) return(c(start,rest0))
+  return(c(start,Linebreak80(rest0)))
+}
+
+
+
+replaceReqDistrPkgversion <- function(text, version, pkg="distr"){
+     if(!is.na(version)) paste(gsub(paste(pkg,"[ ]*\\([^\\)]+\\)",
+                            sep=""),version,text),collapse=" ")
+  }
+
 replaceReqRversion <- function(text,version){
-     if(!is.na(version)) gsub("^R[ ]*\\([^\\)]+\\)",version,text)
+     if(!is.na(version)) paste(gsub("^R[ ]*\\([^\\)]+\\)",version,text),collapse=" ")
   }
 
 ## needs: getRevNr() in getRevNr.R in  utils/ e.g.
@@ -68,6 +143,7 @@
                         ## (otherwise need full URL as arg pathRepo
     withlogin = TRUE,   ### do we need option --login (yes in cygwin, don't know in Linux)
     ReqRVersion = NA, ## do we change required R-versions?
+    ReqDistrPkgVersion = NA, ## do we change required distr-versions?
     PathToBash = "C:/cygwin64/bin/bash",  ## path to bash
     PathToreadsvnlog.sh="C:/rtest/distr/branches/distr-2.4/pkg/utils",
                     ### path to shell script readsvnlog.sh
@@ -143,9 +219,24 @@
          if(!is.na(ReqRVersion[x])){
             xx[,"Depends"] <- replaceReqRversion(xx[,"Depends"],ReqRVersion[x])
          }
+         if(is.list(ReqDistrPkgVersion)){
+            if(length(ReqDistrPkgVersion[[x]])&&!is.na(ReqDistrPkgVersion[[x]])){
+               pkgnms <- names(ReqDistrPkgVersion[[x]])
+               colnmsxx <- colnames(xx)
+               toCheckField <- c("Depends","Imports","Suggests","Enhances")
+               for(pkgC in pkgnms){
+                   if(!is.na(ReqDistrPkgVersion[[x]][pkgC])){
+                       for(chkf in  toCheckField){
+                          if(chkf %in% colnmsxx)
+                            xx[,chkf] <- replaceReqDistrPkgversion(xx[,chkf],ReqDistrPkgVersion[[x]][pkgC],pkgC)
+                       }
+                   }
+               }
+            }
+         }
          print(xx[,names])
-
-         write.dcf(xx, file=FN,width=1.2*getOption("width"))
+#         print(xx)
+         write.dcf(xx, indent = 12, file=FN,width=95)
          if(withPackageHelpUpdate)
             updatePackageHelp(package=file.path("pkg",x))
        })

Modified: pkg/utils/DESCRIPTIONutilsExamples.R
===================================================================
--- pkg/utils/DESCRIPTIONutilsExamples.R	2019-03-12 09:22:38 UTC (rev 1324)
+++ pkg/utils/DESCRIPTIONutilsExamples.R	2019-03-13 18:58:03 UTC (rev 1325)
@@ -137,11 +137,18 @@
 Names <- c("Version")
 Values <- matrix(c("2.8.0"),1,length(Pkgs))
 ReqRVersion0 <- c(NA,rep("R(>= 3.4)",length(Pkgs)-1))
+ReqDistrPkgVersion0 <- vector("list",length(Pkgs))
+names(ReqDistrPkgVersion0) <- Pkgs
+ReqDistrPkgVersion0[["RandVar"]] <- NA
+for(pk in Pkgs[-1]) ReqDistrPkgVersion0[[pk]] <- c("distr"="distr(>= 2.8.0)",
+            "distrEx"="distrEx(>= 2.8.0)","distrMod"="distrMod(>= 2.8.0)",
+            "RandVar"="RandVar(>= 1.2.0)")
 colnames(Values) <- names(ReqRVersion0) <- Pkgs
-rownames(Values) <- Names
+rownames(Values)  <- Names
 Values["Version",1] <- "0.9.6"
 changeDescription(startDir = "C:/rtest/distr",names=Names,
-                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0)
+                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0,
+                  ReqDistrPkgVersion =ReqDistrPkgVersion0)
 updateHTMLpages(pkgVersions = c(rep("2.8.0",9),"1.2.0"))
 }
 
@@ -152,11 +159,18 @@
 Names <- c("Version")
 Values <- matrix(c("2.8.0"),1,length(Pkgs))
 ReqRVersion0 <- c(NA,rep("R(>= 3.4)",length(Pkgs)-1))
-colnames(Values) <- Pkgs
-rownames(Values) <- names(ReqRVersion0) <- Names
+ReqDistrPkgVersion0 <- vector("list",length(Pkgs))
+names(ReqDistrPkgVersion0) <- Pkgs
+ReqDistrPkgVersion0[["RandVar"]] <- NA
+for(pk in Pkgs[-1]) ReqDistrPkgVersion0[[pk]] <- c("distr"="distr(>= 2.8.0)",
+            "distrEx"="distrEx(>= 2.8.0)","distrMod"="distrMod(>= 2.8.0)",
+            "RandVar"="RandVar(>= 1.2.0)")
+colnames(Values) <- names(ReqRVersion0) <- Pkgs
+rownames(Values)  <- Names
 Values["Version",1] <- "0.9.6"
 changeDescription(startDir = "C:/rtest/distr/branches/distr-2.8",names=Names,
-                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0)
+                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0,
+                  ReqDistrPkgVersion =ReqDistrPkgVersion0)
 }
 
 if(FALSE){## Version 2.9 in branch
@@ -166,11 +180,18 @@
 Names <- c("Version")
 Values <- matrix(c("2.9.0"),1,length(Pkgs))
 ReqRVersion0 <- c(NA,rep("R(>= 3.4)",length(Pkgs)-1))
-colnames(Values) <- Pkgs
-rownames(Values) <- names(ReqRVersion0) <- Names
+ReqDistrPkgVersion0 <- vector("list",length(Pkgs))
+names(ReqDistrPkgVersion0) <- Pkgs
+ReqDistrPkgVersion0[["RandVar"]] <- NA
+for(pk in Pkgs[-1]) ReqDistrPkgVersion0[[pk]] <- c("distr"="distr(>= 2.8.0)",
+            "distrEx"="distrEx(>= 2.8.0)","distrMod"="distrMod(>= 2.8.0)",
+            "RandVar"="RandVar(>= 1.2.0)")
+colnames(Values) <- names(ReqRVersion0) <- Pkgs
+rownames(Values)  <- Names
 Values["Version",1] <- "0.9.7"
 changeDescription(startDir = "C:/rtest/distr/branches/distr-2.9",names=Names,
-                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0)
+                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0,
+                  ReqDistrPkgVersion =ReqDistrPkgVersion0)
 }
 
 if(FALSE){## Version 1.2 in trunk
@@ -178,10 +199,20 @@
 Names <- c("Version")
 Values <- matrix(c("1.2.0"),1,length(Pkgs))
 ReqRVersion0 <- rep("R(>= 3.4)",length(Pkgs))
+ReqDistrPkgVersion0 <- vector("list",length(Pkgs))
+names(ReqDistrPkgVersion0) <- Pkgs
+ReqDistrPkgVersion0[["RandVar"]] <- NA
+for(pk in Pkgs[-1]) ReqDistrPkgVersion0[[pk]] <- c("distr"="distr(>= 2.8.0)",
+            "distrEx"="distrEx(>= 2.8.0)","distrMod"="distrMod(>= 2.8.0)",
+            "RandVar"="RandVar(>= 1.2.0)", "RobAStBase"="RobAStBase(>= 1.2.0)",
+            "ROptEst"="ROptEst(>= 1.2.0)", "ROptEstOld"="ROptEstOld(>= 1.2.0)",
+            "RobAStRDA"="RobAStRDA(>= 1.2.0)")
 colnames(Values) <- names(ReqRVersion0)<- Pkgs
 rownames(Values)  <- Names
 
-changeDescription(startDir = "C:/rtest/robast/",names=Names,pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0)
+changeDescription(startDir = "C:/rtest/robast/",names=Names,pkgs=Pkgs,
+                  values=Values,ReqRVersion =ReqRVersion0,
+                  ReqDistrPkgVersion =ReqDistrPkgVersion0)
 }
 
 if(FALSE){## Version 1.2 in branch
@@ -189,9 +220,19 @@
 Names <- c("Version")
 Values <- matrix(c("1.2.0"),1,length(Pkgs))
 ReqRVersion0 <- rep("R(>= 3.4)",length(Pkgs))
-colnames(Values) <- names(ReqRVersion0)<- Pkgs
+ReqDistrPkgVersion0 <- vector("list",length(Pkgs))
+names(ReqDistrPkgVersion0) <- Pkgs
+ReqDistrPkgVersion0[["RandVar"]] <- NA
+for(pk in Pkgs[-1]) ReqDistrPkgVersion0[[pk]] <- c("distr"="distr(>= 2.8.0)",
+            "distrEx"="distrEx(>= 2.8.0)","distrMod"="distrMod(>= 2.8.0)",
+            "RandVar"="RandVar(>= 1.2.0)", "RobAStBase"="RobAStBase(>= 1.2.0)",
+            "ROptEst"="ROptEst(>= 1.2.0)", "ROptEstOld"="ROptEstOld(>= 1.2.0)",
+            "RobAStRDA"="RobAStRDA(>= 1.2.0)")
+colnames(Values) <- names(ReqRVersion0) <- Pkgs
 rownames(Values)  <- Names
-changeDescription(startDir = "C:/rtest/robast/branches/robast-1.2",names=Names,pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0)
+changeDescription(startDir = "C:/rtest/robast/branches/robast-1.2",names=Names,
+                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0,
+                  ReqDistrPkgVersion =ReqDistrPkgVersion0)
 }
 
 if(FALSE){## Version 1.3 in branch
@@ -199,7 +240,17 @@
 Names <- c("Version")
 Values <- matrix(c("1.3.0"),1,length(Pkgs))
 ReqRVersion0 <- rep("R(>= 3.4)",length(Pkgs))
+ReqDistrPkgVersion0 <- vector("list",length(Pkgs))
+names(ReqDistrPkgVersion0) <- Pkgs
+ReqDistrPkgVersion0[["RandVar"]] <- NA
+for(pk in Pkgs[-1]) ReqDistrPkgVersion0[[pk]] <- c("distr"="distr(>= 2.8.0)",
+            "distrEx"="distrEx(>= 2.8.0)","distrMod"="distrMod(>= 2.8.0)",
+            "RandVar"="RandVar(>= 1.2.0)", "RobAStBase"="RobAStBase(>= 1.2.0)",
+            "ROptEst"="ROptEst(>= 1.2.0)", "ROptEstOld"="ROptEstOld(>= 1.2.0)",
+            "RobAStRDA"="RobAStRDA(>= 1.2.0)")
 colnames(Values) <- names(ReqRVersion0)<- Pkgs
 rownames(Values)  <- Names
-changeDescription(startDir = "C:/rtest/robast/branches/robast-1.3",names=Names,pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0)
+changeDescription(startDir = "C:/rtest/robast/branches/robast-1.3",names=Names,
+                  pkgs=Pkgs, values=Values,ReqRVersion =ReqRVersion0,
+                  ReqDistrPkgVersion =ReqDistrPkgVersion0)
 }

Modified: pkg/utils/README-R-utils
===================================================================
--- pkg/utils/README-R-utils	2019-03-12 09:22:38 UTC (rev 1324)
+++ pkg/utils/README-R-utils	2019-03-13 18:58:03 UTC (rev 1325)
@@ -80,6 +80,12 @@
 ##         inRforge: shall we use r-forge as repository
 ##                  (otherwise need full URL as arg pathRepo
 ##         withlogin: do we need option --login (yes in cygwin, don't know in Linux)
+##         ReqRVersion = NA, if not NA a (named) vector of length(pkgs) with the required
+##                       R-versions per package in Syntax R(>=...)
+##         ReqDistrPkgVersion = NA, if not NA a (named) list of length(pkgs) with an entry
+##                       for each package; for each package the entry is a named character 
+##                       vector with the required versions of packages of form 
+##                       "<pkg>"="<pkg>(>=..)"
 ##         PathToBash: path to bash
 ##         PathToreadsvnlog.sh:  path to shell script readsvnlog.sh
 ##         tmpfile: some tmpfile to which we write the results temporarily; 



More information about the Distr-commits mailing list