[Roxygen-commits] r52 - in pkg: R sandbox

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


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

Modified:
   pkg/R/Rd.R
   pkg/R/string.R
   pkg/sandbox/Rd.R
Log:
recursive word.ref much faster


Modified: pkg/R/Rd.R
===================================================================
--- pkg/R/Rd.R	2008-07-19 21:06:21 UTC (rev 51)
+++ pkg/R/Rd.R	2008-07-19 21:06:32 UTC (rev 52)
@@ -1,18 +1,6 @@
 #' @include list.R string.R functional.R
 Rd <- function(partita) {
-  relevators <- c('name',
-                  'aliases',
-                  'title',
-                  'description',
-                  'usage',
-                  'param',
-                  'return',
-                  'references',
-                  'note',
-                  'author',
-                  'seealso',
-                  'examples',
-                  'keywords')
+  ## TODO: param
 
   Rd.expression <- function(key, expression)
     sprintf('\\%s{%s}\n', key, expression)

Modified: pkg/R/string.R
===================================================================
--- pkg/R/string.R	2008-07-19 21:06:21 UTC (rev 51)
+++ pkg/R/string.R	2008-07-19 21:06:32 UTC (rev 52)
@@ -15,26 +15,38 @@
 
 ## Major source of inefficiency; resort to a words-string datatype
 ## with pre-delineated words?
-words.default <- function(string, matter) gregexpr(matter, string)[[1]]
+words <- function(string) gregexpr(MATTER, string)[[1]]
 
-nwords.default <- function(string, words) length(words(string))
+nwords <- function(string) length(words(string))
 
-word.ref.default <- function(string, n, words) {
-  words <- words(string)
-  start <- words[[n]]
-  length <- attributes(words)$match.length[[n]]
-  end <- start + length - 1
-  list(start=start, end=end)
+## word.ref <- function(string, n) {
+##   words <- words(string)
+##   start <- words[[n]]
+##   length <- attributes(words)$match.length[[n]]
+##   end <- start + length - 1
+##   list(start=start, end=end)
+## }
+
+word.ref <- function(string, n) {
+  continue <- function(string, n, init) {
+    word <- regexpr(MATTER, string)
+    start <- word[[1]]
+    length <- attributes(word)$match.length[[1]]
+    end <- start + length
+    if (n <= 1) list(start=start + init, end=end + init)
+    else continue(substr(string, end, nchar(string)), n - 1, init + length)
+  }
+  continue(string, n, 0)
 }
 
-strcar.default <- function(string, word.ref) {
+strcar <- function(string) {
   if (is.null.string(string))
     stop('CARing null-string')
   ref <- word.ref(string, 1)
-  substr(string, ref$start, ref$end)
+  substr(string, ref$start, ref$end - 1)
 }
 
-strcdr.default <- function(string, nwords, word.ref) {
+strcdr <- function(string) {
   if (is.null.string(string))
     stop('CDRing null-string')
   nwords <- nwords(string)
@@ -44,12 +56,12 @@
     substr(string, word.ref(string, 2)$start, nchar(string))
 }
 
-words <- Curry(words.default, matter=MATTER)
-
-nwords <- Curry(nwords.default, words=words)
-
-word.ref <- Curry(word.ref.default, words=words)
-
-strcar <- Curry(strcar.default, word.ref=word.ref)
-
-strcdr <- Curry(strcdr.default, nwords=nwords, word.ref=word.ref)
+debug <- function(...) {
+  values <- list(...)
+  var.values <- zip.list(attributes(values)$names, values)
+  cat(Reduce(function(pairs, var.value)
+             Curry(paste, sep='')
+             (pairs, sprintf('%s: %s; ', car(var.value), cadr(var.value))),
+             var.values,
+             NULL), '\n')
+}

Modified: pkg/sandbox/Rd.R
===================================================================
--- pkg/sandbox/Rd.R	2008-07-19 21:06:21 UTC (rev 51)
+++ pkg/sandbox/Rd.R	2008-07-19 21:06:32 UTC (rev 52)
@@ -1,7 +1,7 @@
 source('../R/functional.R')
 source('../R/list.R')
 source('../R/parse.R')
-source('../R/strings.R')
+source('../R/string.R')
 source('../R/Rd.R')
 
 FILE <- 'example-Rd-nlm.R'



More information about the Roxygen-commits mailing list