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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jul 20 07:07:46 CEST 2008


Author: pcd
Date: 2008-07-20 07:07:46 +0200 (Sun, 20 Jul 2008)
New Revision: 59

Modified:
   pkg/R/Rd.R
   pkg/R/namespace.R
   pkg/R/parse.R
   pkg/R/string.R
   pkg/sandbox/Rd.R
   pkg/sandbox/example-S3-mcpi.R
   pkg/sandbox/namespace.R
Log:
simplified namespace roclet; pre-roclet-generalization


Modified: pkg/R/Rd.R
===================================================================
--- pkg/R/Rd.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/R/Rd.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -1,4 +1,6 @@
-#' @include list.R string.R functional.R
+#' @include list.R
+#' @include string.R
+#' @include functional.R
 Rd <- function(partita) {
   Rd.expression <- function(key, ...)
     sprintf('\\%s%s\n',
@@ -94,7 +96,7 @@
 
   ## Parse the rest first for side-effects (i.e. parameter-gathering).
   for (partitum in partita)
-    for (key.value in zip.list(attributes(partitum)$names, partitum))
+    for (key.value in key.values(partitum))
       do.call(parser(car(key.value)), cdr(key.value))
 
   ## Then parse the arguments.

Modified: pkg/R/namespace.R
===================================================================
--- pkg/R/namespace.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/R/namespace.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -1,45 +1,31 @@
-#' @include string.R functional.R
+#' @include string.R
+#' @include functional.R
+#' @include list.R
+#' Revamp to use noop; relevata-model unnecessary.
 namespace <- function(partita) {
-  parse.default <- function(procedure, parameters)
-    sprintf('%s(%s)', procedure, strmap(Identity, ', ', parameters))
+  parse.default <- function(proc, parms)
+    cat(sprintf('%s(%s)\n', proc, strmap(Identity, ', ', parms)))
   
-  parse.exportClass <- function(procedure, parameters)
-    parse.default('exportClasses', parameters)
+  parsers <- list(exportClass=function(proc, parms)
+                  parse.default('exportClasses', parms),
+                  exportMethod=function(proc, parms)
+                  parse.default('exportMethods', parms),
+                  export=parse.default,
+                  exportPattern=parse.default,
+                  S3method=parse.default,
+                  import=parse.default,
+                  importFrom=parse.default,
+                  importClassesFrom=parse.default,
+                  importMethodsFrom=parse.default)
 
-  parse.exportMethod <- function(procedure, parameters)
-    parse.default('exportMethods', parameters)
+  parse.noop <- function(procedure, parameters) NULL
 
-  parsers <- list(exportClass=parse.exportClass,
-                  exportMethod=parse.exportMethod)
+  parser <- function(procedure)
+    if (is.null(f <- parsers[[procedure]])) parse.noop else f
 
-  relevators <- c('export',
-                  'exportClass',
-                  'exportMethod',
-                  'exportPattern',
-                  'S3method',
-                  'import',
-                  'importFrom',
-                  'importClassesFrom',
-                  'importMethodsFrom')
-  relevata <-
-    Reduce(append,
-           Map(function(partitum)
-               Filter(function(key.value) car(key.value) %in% relevators,
-                      zip.list(attributes(partitum)$names,
-                               partitum)),
-               partita),
-           NULL)
-  directives <-
-    Map(function(relevatum) {
-      procedure <- car(relevatum)
-      parameters <- cadr(relevatum)
-      parser <- parsers[[procedure]]
-      if (is.null(parser))
-        parse.default(procedure, parameters)
-      else
-        parser(procedure, parameters)
-    },
-        relevata)
-  for (directive in directives)
-    cat(directive, "\n")
+  for (partitum in partita)
+    for (key.value in key.values(partitum)) {
+      key <- car(key.value)
+      do.call(parser(key), list(key, cdr(key.value)))
+    }
 }

Modified: pkg/R/parse.R
===================================================================
--- pkg/R/parse.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/R/parse.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -1,4 +1,5 @@
-#' @include string.R list.R
+#' @include string.R
+#' @include list.R
 LINE.DELIMITER <- '#\''
 TAG.DELIMITER <- '@'
 
@@ -50,7 +51,7 @@
   as.list(structure(rest, names=key))
 
 parse.preref <- function(key, rest) {
-  parse.warning(sprintf('<%s>', key), 'is an unknown key')
+  parse.warning(key, 'is an unknown key')
   parse.default(key, rest)
 }
 
@@ -109,6 +110,8 @@
 
 parse.author <- Curry(parse.value, key='author')
 
+parse.include <- Curry(parse.value, key='include')
+
 parse.name.description <- function(key, rest) {
   name <- strcar(rest)
   rest <- strcdr(rest)
@@ -127,6 +130,8 @@
 parse.name.internal <- function(key, name) {
   if (is.null.string(name))
     parse.error(key, 'requires a name')
+  else if (nwords(name) > 1)
+    parse.warning(key, 'ignoring extra arguments')
   parse.default(key, strcar(name))
 }
 

Modified: pkg/R/string.R
===================================================================
--- pkg/R/string.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/R/string.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -1,4 +1,5 @@
-#' @include functional.R @include list.R
+#' @include functional.R
+#' @include list.R
 SPACE <- '[[:space:]]+'
 MATTER <- '[^[:space:]]+'
 NIL.STRING <- ''
@@ -14,6 +15,11 @@
 
 is.null.string <- function(string) regexpr(MATTER, string) < 0
 
+nwords <- function(string) {
+  if (is.null.string(string)) 0
+  else length(gregexpr(MATTER, string))
+}
+
 word.ref <- function(string, n) {
   continue <- function(string, n, init) {
     word <- regexpr(MATTER, string)

Modified: pkg/sandbox/Rd.R
===================================================================
--- pkg/sandbox/Rd.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/sandbox/Rd.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -2,12 +2,13 @@
 source('../R/list.R')
 source('../R/parse.R')
 source('../R/string.R')
+source('../R/roclet.R')
 source('../R/Rd.R')
 
-FILE <- 'example-Rd-nlm.R'
+FILES <- list('example-Rd-nlm.R')
 
 argv <- commandArgs(trailingOnly=T)
 argc <- length(argv)
-file <- ifelse(argc > 0, car(argv), FILE)
+files <- ifelse(argc > 0, as.list(argv), FILES)
 
-Rd(parse.file(file))
+Rd(do.call(parse.file, files))

Modified: pkg/sandbox/example-S3-mcpi.R
===================================================================
--- pkg/sandbox/example-S3-mcpi.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/sandbox/example-S3-mcpi.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -6,7 +6,7 @@
 #' @slot pi Estimation of pi
 #' @slot throws Number of throws
 #' @listObject
-NA
+roxygen
 
 #' A monte carlo algorithm to calculate PI. Extended
 #' version which returns the throws.

Modified: pkg/sandbox/namespace.R
===================================================================
--- pkg/sandbox/namespace.R	2008-07-20 05:07:32 UTC (rev 58)
+++ pkg/sandbox/namespace.R	2008-07-20 05:07:46 UTC (rev 59)
@@ -2,6 +2,7 @@
 source('../R/list.R')
 source('../R/string.R')
 source('../R/parse.R')
+source('../R/roclet.R')
 source('../R/namespace.R')
 
 FILES <- list('example-function-mcpi.R',



More information about the Roxygen-commits mailing list