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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 18 13:08:15 CEST 2008


Author: pcd
Date: 2008-06-18 13:08:14 +0200 (Wed, 18 Jun 2008)
New Revision: 37

Modified:
   pkg/R/functional.R
   pkg/R/list.R
   pkg/R/parse.R
   pkg/sandbox/example.R
   pkg/sandbox/main.R
Log:
reintroduce Negate; error messages for parse; import/export keywords; param; clean up main


Modified: pkg/R/functional.R
===================================================================
--- pkg/R/functional.R	2008-06-08 18:14:23 UTC (rev 36)
+++ pkg/R/functional.R	2008-06-18 11:08:14 UTC (rev 37)
@@ -4,3 +4,7 @@
   .orig = list(...);
   function(...) do.call(FUN,c(.orig,list(...)))
 }
+
+## Borrowed from src/library/base/R/funprog.R for pre-2.7 Rs.
+Negate <- function(f)
+  function(...) ! match.fun(f)(...)

Modified: pkg/R/list.R
===================================================================
--- pkg/R/list.R	2008-06-08 18:14:23 UTC (rev 36)
+++ pkg/R/list.R	2008-06-18 11:08:14 UTC (rev 37)
@@ -1,3 +1,5 @@
+source('../R/functional.R')
+
 nil <- list()
 
 is.nil <- function(list)
@@ -36,8 +38,7 @@
 }
 
 is.odd <- function(a) {
-  #Negate(is.even)(a)
-  !is.even(a)
+  Negate(is.even)(a)
 }
 
 zip <- function(zipper, ...) {

Modified: pkg/R/parse.R
===================================================================
--- pkg/R/parse.R	2008-06-08 18:14:23 UTC (rev 36)
+++ pkg/R/parse.R	2008-06-18 11:08:14 UTC (rev 37)
@@ -34,6 +34,9 @@
 
 ## preref parsers
 
+parse.error <- function(key, message)
+  stop(sprintf('@%s %s.', key, message))
+
 parse.preref <- function(...) {
   list(unknown=paste(...))
 }
@@ -47,19 +50,53 @@
 parse.description <- function(expression)
   list(description=expression)
 
-parse.prototype <- function(...)
-  list(prototype=paste(...))
+is.empty <- function(...) is.nil(c(...)) || is.na(car(as.list(...)))
 
-parse.export <- function(...)
-  list(export=T)
+args.to.string <- function(...)
+  ifelse(is.empty(...), NA, paste(...))
 
-parse.name.description <- function(name, ...)
-  list(slot=list(name=name, description=paste(...)))
+parse.default <- function(key, ...)
+  as.list(structure(args.to.string(...), names=key))
 
-parse.slot <- parse.name.description
+## Possibly NA, for which the Roclets can do something more
+## sophisticated with the srcref.
+parse.export <- Curry(parse.default, key='export')
 
-parse.param <- parse.name.description
+parse.value <- function(key, ...)
+  ifelse(is.empty(...),
+         parse.error(key, 'requires a value'),
+         parse.default(key, ...))
+  
+parse.prototype <- Curry(parse.value, key='prototype')
 
+parse.exportClasses <- Curry(parse.value, key='exportClasses')
+
+parse.exportMethods <- Curry(parse.value, key='exportMethods')
+
+parse.exportPattern <- Curry(parse.value, key='exportPattern')
+
+parse.S3method <- Curry(parse.value, key='S3method')
+
+parse.import <- Curry(parse.value, key='import')
+
+parse.importFrom <- Curry(parse.value, key='importFrom')
+
+parse.importClassesFrom <- Curry(parse.value, key='importClassesFrom')
+
+parse.importMethodsFrom <- Curry(parse.value, key='importMethodsFrom')
+
+parse.name.description <- function(key, name, ...)
+  ifelse(any(is.na(name),
+             is.empty(...)),
+         parse.error(key, 'requires a name and description'),
+         as.list(structure(list(list(name=name,
+                                     description=args.to.string(...))),
+                           names=key)))
+
+parse.slot <- Curry(parse.name.description, key='slot')
+
+parse.param <- Curry(parse.name.description, key='param')
+
 ## srcref parsers
 
 parse.srcref <- function(...) nil

Modified: pkg/sandbox/example.R
===================================================================
--- pkg/sandbox/example.R	2008-06-08 18:14:23 UTC (rev 36)
+++ pkg/sandbox/example.R	2008-06-18 11:08:14 UTC (rev 37)
@@ -4,6 +4,7 @@
 #' @slot birthyear The year of birth
 #' @prototype Prototype person is named John Doe
 #'      and born in the year 1971
+#' @export
 setClass('person',
          representation=
          representation(fullname='character',

Modified: pkg/sandbox/main.R
===================================================================
--- pkg/sandbox/main.R	2008-06-08 18:14:23 UTC (rev 36)
+++ pkg/sandbox/main.R	2008-06-18 11:08:14 UTC (rev 37)
@@ -7,8 +7,4 @@
 argc <- length(argv)
 file <- ifelse(argc > 0, car(argv), FILE)
 
-l <- parse.file(file)
-str(l)
-
-
-l1 <- parse.file('example-S4-person.R')
+str(parse.file(file))



More information about the Roxygen-commits mailing list