SCM

SCM Repository

[inlinedocs] Diff of /pkg/inlinedocs/R/parsers.R
ViewVC logotype

Diff of /pkg/inlinedocs/R/parsers.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 308, Fri Oct 21 12:08:39 2011 UTC revision 336, Thu Apr 5 12:44:33 2012 UTC
# Line 1  Line 1 
1    do.not.generate <- structure(function
2    ### Make a Parser Function used to indicate that certain Rd files
3    ### should not be generated.
4    (...
5    ### Character strings indicating Rd files without the .Rd suffix.
6     ){
7      filenames <- c(...)
8      function(docs,...){
9        for(fn in filenames){
10          docs[[fn]] <- list()
11        }
12        docs$.overwrite <- TRUE
13        docs
14      }
15    ### A Parser Function that will delete items from the outer
16    ### Documentation List.
17    },ex=function(){
18      silly.pkg <- system.file("silly",package="inlinedocs")
19      owd <- setwd(tempdir())
20      file.copy(silly.pkg,".",recursive=TRUE)
21    
22      ## define a custom Parser Function that will not generate some Rd
23      ## files
24      custom <- do.not.generate("silly-package","Silly-class")
25      parsers <- c(default.parsers,list(exclude=custom))
26    
27      ## At first, no Rd files in the man subdirectory.
28      man.dir <- file.path("silly","man")
29      dir(man.dir)
30    
31      ## Running package.skeleton.dx will generate bare-bones files for
32      ## those specified in do.not.generate, if they do not exist.
33      package.skeleton.dx("silly",parsers)
34      Rd.files <- c("silly-package.Rd","Silly-class.Rd","silly.example.Rd")
35      Rd.paths <- file.path(man.dir,Rd.files)
36      stopifnot(all(file.exists(Rd.paths)))
37    
38      ## Save the modification times of the Rd files
39      old <- file.info(Rd.paths)$mtime
40    
41      ## However, it will NOT generate Rd for files specified in
42      ## do.not.generate, if they DO exist already.
43      package.skeleton.dx("silly",parsers)
44      mtimes <- data.frame(old,new=file.info(Rd.paths)$mtime)
45      rownames(mtimes) <- Rd.files
46      mtimes$changed <- mtimes$old != mtimes$new
47      print(mtimes)
48      stopifnot(mtimes["silly-package.Rd","changed"]==FALSE)
49      stopifnot(mtimes["Silly-class.Rd","changed"]==FALSE)
50      stopifnot(mtimes["silly.example.Rd","changed"]==TRUE)
51    
52      unlink("silly",recursive=TRUE)
53      setwd(owd)
54    })
55    
56  ### combine lists or character strings  ### combine lists or character strings
57  combine <- function(x,y)UseMethod("combine")  combine <- function(x,y)UseMethod("combine")
58    
# Line 143  Line 198 
198        arg <- gsub("^([^=,]*)[=,].*", "\\1", arg)        arg <- gsub("^([^=,]*)[=,].*", "\\1", arg)
199        ##twutz: remove trailing whitespaces        ##twutz: remove trailing whitespaces
200        arg <- gsub("^([^ \t]*)([ \t]+)$","\\1",arg)        arg <- gsub("^([^ \t]*)([ \t]+)$","\\1",arg)
201        arg <- gsub("...", "\\dots", arg, fix = TRUE)        arg <- gsub("...", "\\dots", arg, fixed = TRUE)
202        paste("item{",arg,"}",sep="")        paste("item{",arg,"}",sep="")
203      } else {      } else {
204        next;        next;
# Line 364  Line 419 
419          ## TDH 2010-06-18 For item{}s in the documentation list names,          ## TDH 2010-06-18 For item{}s in the documentation list names,
420          ## we don't need to have a backslash before, so delete it.          ## we don't need to have a backslash before, so delete it.
421          arg <- gsub("^[\\]+","",arg)          arg <- gsub("^[\\]+","",arg)
422          cur.field <- gsub("...","\\dots",arg,fix=TRUE) ##special case for dots          cur.field <- gsub("...","\\dots",arg,fixed=TRUE) ##special case for dots
423          payload <- comment          payload <- comment
424        } else {        } else {
425          ## this is a describe block, so we need to paste with existing          ## this is a describe block, so we need to paste with existing
# Line 874  Line 929 
929    ## package when we try to process S4 classes defined in code    ## package when we try to process S4 classes defined in code
930    e$.packageName <- "inlinedocs.processor"    e$.packageName <- "inlinedocs.processor"
931    for (i in exprs){    for (i in exprs){
     ## TDH 2011-04-07 Disable this tryCatch since it makes it harder  
     ##to debug errors/warnings in the evaluated code  
   
     ##tryCatch({  
932        eval(i, e)        eval(i, e)
     ##},error=function(e){  
       ##print(e)  
     ##})  
933    }    }
934    objs <- sapply(ls(e),get,e,simplify=FALSE)    objs <- sapply(ls(e),get,e,simplify=FALSE)
935    
936    docs <- list()    docs <- list()
937    
938    ## apply parsers in sequence to code and objs    ## apply parsers in sequence to code and objs
939      if(verbose)cat("Applying parsers:\n")
940    for(i in seq_along(parsers)){    for(i in seq_along(parsers)){
941      N <- names(parsers[i])      N <- names(parsers[i])
942      if(verbose){      if(verbose){
943        if(is.character(N) && N!=""){        if(is.character(N) && N!=""){
944          cat(N," ",sep="")          cat(N,"\n",sep="")
945        }else cat('. ')        }else cat('.\n')
946      }      }
947      p <- parsers[[i]]      p <- parsers[[i]]
948      ## This is the argument list that each parser receives:      ## This is the argument list that each parser receives:
949      L <- p(code=code,objs=objs,docs=docs,env=e,...)      L <- p(code=code,objs=objs,docs=docs,env=e,...)
950        #print(paste(L,"\n"))
951        #if(N=="exclude")browser()
952      docs <- combine(docs,L)      docs <- combine(docs,L)
953    }    }
954    ## post-process to collapse all character vectors    ## post-process to collapse all character vectors
# Line 908  Line 959 
959      }      }
960    }    }
961    if(verbose)cat("\n")    if(verbose)cat("\n")
962    docs    return(docs)
963  ### A list of extracted documentation from code.  ### A list of extracted documentation from code.
964  }  }
965    

Legend:
Removed from v.308  
changed lines
  Added in v.336

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge