[Roxygen-commits] r58 - pkg/R

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


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

Modified:
   pkg/R/Rd.R
   pkg/R/parse.R
Log:
noop for sourceless files


Modified: pkg/R/Rd.R
===================================================================
--- pkg/R/Rd.R	2008-07-19 21:07:58 UTC (rev 57)
+++ pkg/R/Rd.R	2008-07-20 05:07:32 UTC (rev 58)
@@ -48,7 +48,7 @@
     description <- car(paragraphs)
     details <- do.call(paste, append(cdr(paragraphs), list(sep='\n\n')))
     parse.default('description', description)
-    if (!is.null.string(details))
+    if (length(details) > 0 && !is.null.string(details))
       parse.default('details', details)
   }
 
@@ -69,7 +69,8 @@
                  '')
 
   parse.arguments <- function(params)
-    parse.default('arguments', parse.params(params))
+    if (length(params) > 0)
+      parse.default('arguments', parse.params(params))
 
   parse.noop <- function(expression) NULL
 

Modified: pkg/R/parse.R
===================================================================
--- pkg/R/parse.R	2008-07-19 21:07:58 UTC (rev 57)
+++ pkg/R/parse.R	2008-07-20 05:07:32 UTC (rev 58)
@@ -2,6 +2,9 @@
 LINE.DELIMITER <- '#\''
 TAG.DELIMITER <- '@'
 
+#' No-op for sourceless files
+roxygen <- NULL
+
 #' Comment blocks (possibly null) that precede a file's expressions.
 prerefs <- function(srcfile, srcrefs) {
   length.line <- function(lineno)
@@ -157,8 +160,11 @@
 ## Parser lookup
 
 parser.default <- function(key, default) {
-  f <- ls(1, pattern=sprintf('parse.%s', trim(key)))[1]
-  if (is.na(f)) Curry(default, key=key) else f
+  if (is.na(f <- tryCatch(ls(1, pattern=sprintf('parse.%s', trim(key)))[1],
+                          error=function(e) NA)))
+    Curry(default, key=key)
+  else
+    f
 }
 
 parser.preref <- Curry(parser.default, default=parse.preref)
@@ -216,22 +222,31 @@
   srcfile <- attributes(srcref)$srcfile
   lines <- getSrcLines(srcfile, car(srcref), caddr(srcref))
   expression <- parse(text=lines)
-  pivot <- caar(expression)
-  parser <- parser.srcref(as.character(pivot))
-  append(do.call(parser, list(expression)),
-         list(srcref=list(filename=srcfile$filename,
-                lloc=as.vector(srcref))))
-         
+  pivot <- tryCatch(caar(expression), error=function(e) NULL)
+  if (is.null(pivot))
+    nil
+  else {
+    parser <- parser.srcref(as.character(pivot))
+    append(do.call(parser, list(expression)),
+           list(srcref=list(filename=srcfile$filename,
+                  lloc=as.vector(srcref))))
+  }
 }
 
-parse.refs <- function(prerefs.srcrefs)
-  Map(parse.ref, prerefs.srcrefs)
+parse.refs <- function(preref.srcrefs)
+  Map(parse.ref, preref.srcrefs)
 
 parse.file <- function(file) {
   srcfile <- srcfile(file)
   srcrefs <- attributes(parse(srcfile$filename,
                               srcfile=srcfile))$srcref
-  parse.refs(zip.list(prerefs(srcfile, srcrefs), srcrefs))
+  if (length(srcrefs) > 0)
+    parse.refs(zip.list(prerefs(srcfile, srcrefs), srcrefs))
+  else {
+    warning(sprintf('%s has no statements (not even `roxygen\')',
+                    srcfile$filename))
+    nil
+  }
 }
 
 parse.files <- function(...)



More information about the Roxygen-commits mailing list