[Roxygen-commits] r54 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 19 23:07:07 CEST 2008


Author: pcd
Date: 2008-07-19 23:07:06 +0200 (Sat, 19 Jul 2008)
New Revision: 54

Modified:
   pkg/R/namespace.R
   pkg/R/string.R
Log:
recursive strmap


Modified: pkg/R/namespace.R
===================================================================
--- pkg/R/namespace.R	2008-07-19 21:06:42 UTC (rev 53)
+++ pkg/R/namespace.R	2008-07-19 21:07:06 UTC (rev 54)
@@ -1,3 +1,4 @@
+#' @include string.R
 namespace <- function(partita) {
   parse.default <- function(procedure, parameters)
     sprintf('%s(%s)', procedure, gsub(' +', ', ', parameters))

Modified: pkg/R/string.R
===================================================================
--- pkg/R/string.R	2008-07-19 21:06:42 UTC (rev 53)
+++ pkg/R/string.R	2008-07-19 21:07:06 UTC (rev 54)
@@ -1,12 +1,13 @@
-#' @include functional.R
+#' @include functional.R @include list.R
 SPACE <- '[[:space:]]+'
 MATTER <- '[^[:space:]]+'
+NIL.STRING <- ''
 
 trim.left <- function(string)
-  gsub(sprintf('^%s', SPACE), '', string)
+  gsub(sprintf('^%s', SPACE), NIL.STRING, string)
 
 trim.right <- function(string)
-  gsub(sprintf('%s$', SPACE), '', string)
+  gsub(sprintf('%s$', SPACE), NIL.STRING, string)
 
 trim <- function(string)
   Compose(trim.left, trim.right)(string)
@@ -50,12 +51,29 @@
   if (is.null.string(string))
     stop('CDRing null-string')
   nwords <- nwords(string)
-  if (nwords == 1)
-    ''
+  if (nwords == 1) NIL.STRING
   else
     substr(string, word.ref(string, 2)$start, nchar(string))
 }
 
+strcons <- function(consor, consee, sep) {
+  if (is.null.string(consee)) consor
+  else paste(consor, consee, sep=sep)
+}
+
+## General enough to be designated `map'? Should it preserve
+## non-matter?
+strmap <- function(proc, sep, string) {
+  continue <- function(string)
+    if (is.null.string(string))
+      NIL.STRING
+    else
+      strcons(strcar(string),
+              continue(strcdr(string)),
+              sep=sep)
+  continue(string)
+}
+
 debug <- function(...) {
   values <- list(...)
   var.values <- zip.list(attributes(values)$names, values)



More information about the Roxygen-commits mailing list