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 105, Tue May 18 17:32:43 2010 UTC revision 396, Tue Feb 18 13:07:32 2014 UTC
# Line 1  Line 1 
1  ### For each object in the package that satisfies the criterion  #
2  ### checked by subfun, parse source using FUN and return the resulting  ############################################################
3  ### documentation list.  sigString <- function(sig){paste(sig,collapse="_")}
4  forall <- function  ############################################################
5  (FUN,  methodDocName=function
6  ### Function to apply to each element in the package.  ### creates the actual *.Rd filename for a method from its signature and the generic it implements
7   subfun=function(x)TRUE  (genName,sig){
8  ### Function to select subsets of elements of the package, such as    N=paste(genName,"_method__",sigString(sig),sep="")
9  ### is.function. subfun(x)==TRUE means FUN will be applied to x and    N
10  ### the result will be returned.  }
11   ){  # vim:set ff=unix expandtab ts=2 sw=2:
12    function(objs,docs,...){  ############################################################
13      objs <- objs[sapply(objs,subfun)]  setMethod("[",
14      L <- list()      signature(x = "listOfMethods", i = "logical"),
15      for(N in names(docs)){      function
16        o <- objs[[N]]      ### overload the [] operator for objects of class "listOfMethods"
17        L[[N]] <- FUN(src=attr(o,"source"),      (x, i, j, ..., drop = TRUE)
18                      name=N,objs=objs,o=o,docs=docs,doc=docs[[N]],...)      {
19      }         fdef <- x@generic
20      L         object <- new("listOfMethods", arguments = fdef@signature)
21           object@generic <- fdef
22           object@signatures  <- x@signatures[i]
23           object@.Data       <-      x@.Data[i]
24           object@names       <-      x@names[i]
25           #pe(quote(class(object)),environment())
26           object
27    
28    }    }
29  ### A Parser Function.  )
30    ############################################################
31    mmPromptMethods <-  function (genName, filename = NULL, exportedMeths,where)
32      ## this is a copy of R s own promptMehtods functions but
33      ## with an additional argument of the methods to be exported (and documented)
34    {
35    
36        genExported  <- !is.null(exportedMeths)
37    
38        escape <- function(txt) gsub("%", "\\\\%", txt)
39        packageString <- ""
40        fdef <- getGeneric(genName,where=where)
41        if (!isGeneric(f=genName ,where=where,fdef = fdef))
42            stop(gettextf("no generic function found corresponding to %s",
43                sQuote(genName)), domain = NA)
44        methods <- findMethods(fdef,where=where)
45    
46        #where <- .genEnv(fdef, topenv(parent.frame()))
47        #if (!identical(where, .GlobalEnv))
48        #    packageString <- sprintf("in Package \\pkg{%s}",
49        #        getPackageName(where))
50        fullName <- utils:::topicName("methods", genName)
51    
52        n <- length(methods)
53        labels <- character(n)
54        aliases <- character(n)
55        signatures <- findMethodSignatures(methods = methods, target = TRUE)
56        args <- colnames(signatures)
57        for (i in seq_len(n)) {
58            sigi <- signatures[i, ]
59            labels[[i]] <- sprintf("\\code{signature(%s)}", paste(sprintf("%s = \"%s\"",
60                args, escape(sigi)), collapse = ", "))
61            aliases[[i]] <- paste0("\\alias{", utils:::topicName("method",
62                c(genName, signatures[i, ])), "}")
63        }
64        ####
65        if(genExported){
66          exportedSignatures <-findMethodSignatures(methods =exportedMeths, target = TRUE)
67         # #pp("exportedSignatures",environment())
68          n=nrow(exportedSignatures)
69          labels <- character(n)
70          items<- character(n)
71          args <- colnames(exportedSignatures)
72          for (i in seq_len(n)) {
73            sigi <- exportedSignatures[i, ]
74            N <- methodDocName(genName,sigi)
75            labels[[i]] <- sprintf("\\code{signature(%s)}", paste(sprintf("%s = \"%s\"",
76                args, escape(sigi)), collapse = ", "))
77            items[[i]]<- paste0("    \\item{", labels[[i]], "}{\n      \\code{\\link{",N,"}}  \n    }")
78    
79  }  }
80          des <- paste0(
81            "\\description{\n ~~ Methods for function",
82            " \\code{", genName, "}",
83            sub("^in Package", "in package", packageString),
84            " ~~\n}"
85          )
86    
87  ### For each function in the package, do something.        text <- c("\\section{Methods}{\n  \\describe{", items, "\n  }\n}")
 forfun <- function(FUN)forall(FUN,is.function)  
88    
89  ### Parsers for each object/function that are constructed      }else{
90  ### automatically. This is a named list, each element is a list of 2        des <- paste0(
91  ### elements: forfun/forall, then a parser function for an individual          "\\description{\n All methods for function",
92  ### object.          " \\code{", genName, "} ",
93  forall.parsers <-          "are intended for internal use inside the package only. \n}"
94    list(## Extract lots of info from normal functions.        )
95         parsefun=list(forfun,function(src,name,...){        #item<-'
96           extract.docs.fun(src,name)        #All methods for this generic are privat. (not exported into the namespace).
97         }),        #To discourage use outside the package the documentation is truncated.
98         ## Fill in author from DESCRIPTION and titles.        #'
99         author.from.description=list(forall,function(desc,...){        #text <- c("\\section{Methods}{\n\\describe{", item, "}\n}")
100           list(author=desc[,"Maintainer"])        text <- "" #no method section at all
101         }),      }
102         ## The format section sometimes causes problems, so erase it.      aliasText <- c(paste0("\\alias{", escape(fullName), "}"),
103         erase.format=list(forall,function(...){          escape(aliases))
104           list(format="")      if (identical(filename, FALSE))
105         }),          return(c(aliasText, text))
106         ## Convert the function name to a title.      if (is.null(filename) || identical(filename, TRUE))
107         title.from.name=list(forall,function(name,doc,...){          filename <- paste0(fullName, ".Rd")
108           if("title"%in%names(doc))list() else      Rdtxt <- list(name = paste0("\\name{", fullName, "}"), type = "\\docType{methods}",
109           list(title=gsub("[._]"," ",name))          aliases = aliasText, title = sprintf("\\title{ ~~ Methods for Function \\code{%s} %s ~~}",
110         }),              genName, packageString), description = des
111         ## Get examples for FUN from the file test/FUN.R          , `section{Methods}` = text,
112         examples.from.testfile=list(forfun,function(name,...){          keywords = c("\\keyword{methods}", "\\keyword{ ~~ other possible keyword(s) ~~ }"))
113           tfile <- file.path("..","tests",paste(name,".R",sep=""))      if (is.na(filename))
114           if(file.exists(tfile))          return(Rdtxt)
115             list(examples=paste(readLines(tfile),collapse="\n"))      cat(unlist(Rdtxt), file = filename, sep = "\n")
116           else list()      print(paste("A shell of methods documentation has been written",filename))
117         }),      invisible(filename)
118         ## Get examples from inline definitions after return()  }
        examples.after.return=list(forfun,function(name,src,...){  
          coll <- paste(src,collapse="\n")  
          thispre <- gsub("^[\\^]","",prefix)  
          FIND <- paste("(return|UseMethod)[(][^\\n]*\\n",thispre,sep="")  
          m <- regexpr(FIND,coll)  
          if(m[1]==-1)return(list())  
          after <- substr(coll,m[1],nchar(coll))  
          FIND <-  
            paste("[^\\n]*",# rest of the return line  
                  "((?:\\n###[^\\n]*)+)",#comment value lines \\1  
                  "([\\w\\W]*)[}]",#examples \\2  
                  sep="")  
          SEP <- "-/-/-/-/-=====-----"  
          REP <- paste("\\1",SEP,"\\2",sep="")  
          r <- strsplit(gsub(FIND,REP,after,perl=TRUE),split=SEP)[[1]]  
          l <- strsplit(r,split="\n")  
          excode <- c(l[[2]],"")  
          if(length(l)<2||paste(excode,collapse="")=="")return(list())  
          prefixes <- gsub("(\\s*).*","\\1",excode,perl=TRUE)[grep("\\w",excode)]  
          FIND <- prefixes[which.min(nchar(prefixes))]  
          list(examples=paste(sub(FIND,"",excode),collapse="\n"),  
               value=decomment(l[[1]][-1]))  
        }))  
119    
120  ### List of parser functions that operate on single objects. This list  ############################################################
121  ### is useful for testing these functions, ie  removeComma <- function(str){
122  ### lonely$parsefun(attr(extract.docs.file,"source"),"extract.docs.file")    if(grepl(",",str)){
123  lonely <- sapply(forall.parsers,function(L)L[[2]])       str <- strsplit(str,",")[[1]][[1]]
124      }
125      return(str)
126    }
127    ############################################################
128    exported=function
129    ### a helper soon to read the NAMESPACE file, soon to be replaced by Rs own function
130    (pattern,tD){
131      ##pp("tD",environment())
132      #pe(quote(getwd()),environment())
133      # for simpler parsing we dont allow every possible
134      # export statement but assume the form
135      # export(
136      #  firstFunc,
137      #  secondFunc
138      # )
139      ns=readLines(file.path(tD,"NAMESPACE"))
140      if(any(grepl(pattern,ns))){
141        fl=grep(pattern,ns)[[1]]
142        # start search for closing ")" at the opening one and
143        # use only the next ")" if there are several
144        ll= grep("\\)",ns[fl:length(ns)])[[1]]+fl-1
145        if (ll==fl+1){
146          return(NULL)
147        }else{
148          trunks= unlist(lapply(ns[(fl+1):(ll-1)],removeComma))
149          return(trunks)
150        }
151      }else{
152        return(NULL)
153      }
154    }
155    ############################################################
156    exportedFunctions=function
157    ### get the exported functions from the NAMESPACE file
158    (tD){
159      funcNames=exported("export\\(",tD)
160      #pp("funcNames",environment())
161      return(funcNames)
162    }
163    ############################################################
164    exportedGenerics=function
165    ### get the exported generic functions from the NAMESPACE file
166    (tD){
167      # note that there is only a exportMethods statement available
168      funcNames=exported("exportMethods",tD)
169      return(funcNames)
170    }
171    ############################################################
172    exportedClasses=function
173    ### get the exported Classes from the NAMESPACE file
174    (tD){
175      classnames=exported("exportClasses",tD)
176      return(classnames)
177    }
178    ############################################################
179    methodTable <- function(exprs,e){
180      gens=list() ## a list of generic functions that are mentioned in setMethod statements within the code to be documented
181      for ( k in 1:length(exprs)){
182        lang <- exprs[[k]]
183        chars <- as.character(lang)
184        ##pp("chars",environment())
185        expr.type <- chars[[1]]
186        if (expr.type == "setMethod"){
187          NamedArgs=rewriteSetMethodArgs(lang)
188          nameOfGeneric<-NamedArgs[["f"]]
189          methSig <- eval(NamedArgs[["signature"]],e)
190          gens[[nameOfGeneric]] <- unique(c(gens[[nameOfGeneric]],list(methSig)))
191        }
192      }
193      gens
194    }
195    ############################################################
196    allClasses <- function(env){
197      getClasses(where=env)
198    }
199    ############################################################
200    hiddenClasses <- function(env,pkgDir){
201      setdiff(allClasses(env),exportedClasses(pkgDir))
202    }
203    ############################################################
204    # now find all Generics whose src can be found
205    GenHasSrc=function
206    ### This function tells us if we can find a src reference for this generic
207    (genName,e)
208    {!is.null(getSrcref(getGeneric(genName,where=e)))}
209    
210  extract.docs.file <- function # Extract documentation from a file  
211  ### Parse R code to extract inline documentation from comments around  # we now want to find all Generics that have at least one Method where we can get at the source
212  ### each function. These are not able to be retreived simply by  ############################################################
213  ### looking at the "source" attribute. This is a Parser Function that  methSrc=function
214  ### can be used in the parser list of package.skeleton.dx().  ### get at the src of a method given as  an MethodDefinition object
215  (code,  (MethodDefinition){getSrcref(unRematchDefinition(MethodDefinition))}
216  ### Code lines in a character vector containing multiple R objects to  ############################################################
217  ### parse for documentation.  methSig=function
218   objs,  ### Extract the definition as text from an MethodDefinition object
219  ### The objects defined in the code.  (MethodDefinition){attr(MethodDefinition,"defined")}
220   ...  ############################################################
221  ### ignored  MethodHasSrc=function(MethodDefinition)
222   ){  ### This function tells if we can find a src reference for this method
223    parsed <- extract.file.parse(code)  {!is.null(methSrc(MethodDefinition))}
224    extract.docs.try <- function(o,on)  ############################################################
225    MethodSignatureHasOnlyExportedClasses=function(MethodDefinition,env,pkgDir)
226    ### check if all the classes in the signature are exported in the NAMESPACE file.
227    ### This information is needed to decide which Methods we want to document in cases
228    ### where the documentations is restricted to the exported NAMESPACE
229      {      {
230        ## Note: we could use parsed information here too, but that    sigStr=as.character(methSig(MethodDefinition))
231        ## would produce different results for setMethodS3 etc.    hiddCls <- hiddenClasses(env,pkgDir)
232        doc <- list()    intersection <- intersect(sigStr,hiddCls)
233        if ( !is.null(parsed[[on]]) ){    res <- (length(intersection)==0)
234          if ( !is.na(parsed[[on]]@code[1]) ){ # no code given for generics    res
           doc$definition <- paste(parsed[[on]]@code,collapse="\n")  
235          }          }
236          if(!"description"%in%names(doc) && !is.na(parsed[[on]]@description) ){  ############################################################
237            doc$description <- parsed[[on]]@description  MethodsWithSrcRefForGen=function
238    ### Not all methods for a Generic are defined in the src we want to document.
239    ### This function helps to find the methods we want.
240    (genName,env){
241      l=findMethods(genName,where=env)[sapply(findMethods(genName,where=env),MethodHasSrc)]
242      #class(l)<-"methods"
243      l
244    }
245    ############################################################
246    GenHasAnyMethodWithSrc=function
247    ### function to check if we have a src reference for any of the methods of this generic
248    ### This helps to decide how the *-methods.Rd file should look like for this generic
249    (genName,env){
250      methDefs <- findMethods(genName,where=env)
251      ##pp("methDefs)
252      any(sapply(
253        methDefs,
254        MethodHasSrc))
255    }
256    ############################################################
257    GenHasAnyExposedMethod=function
258    ### function used to check if a GenericFunction has any method where the whole signature consist of classes exported in the namespace
259    (genName,env,pkgDir){
260      decide=function(MethodDescription){
261        MethodSignatureHasOnlyExportedClasses(MethodDescription,env,pkgDir)
262      }
263      hasExposedMethod <- any(
264          sapply(
265            findMethods(genName,where=env)
266            ,decide
267          )
268      )
269      #pp("genName",environment())
270      #pp("hasExposedMethod",environment())
271      hasExposedMethod
272    }
273    ############################################################
274    documentableMeths<- function(e){
275      # now find out which generics have any documentable methods
276      allGens=as.character(getGenerics(where=e))
277      ##pp("allGens",environment())
278      decide=function(genName){
279        GenHasAnyMethodWithSrc(genName,e)
280      }
281      GensWithDocMethods=allGens[unlist(sapply(allGens,decide))]
282      ##pp("GensWithDocMethods",environment())
283      # now we can make a list of list
284      # containing the Methods we want to documents ordered after the name of there Generics
285      documentableMeths=list()
286      for (genName in GensWithDocMethods){
287            documentableMeths[[genName]]<-MethodsWithSrcRefForGen(genName,e)
288      }
289      documentableMeths
290    }
291    ############################################################
292    exportedDocumentableMeths<- function(e,pkgDir){
293      decide1=function(genName){
294         GenHasAnyExposedMethod(genName,e,pkgDir)
295      }
296      dm <- documentableMeths(e)
297      indices=unlist(sapply(names(dm),decide1))
298      #pp("indices",environment())
299      newGens <- dm[indices]
300      decide2 <-  function(MethodDescription){
301        MethodSignatureHasOnlyExportedClasses(MethodDescription,e,pkgDir)
302      }
303      for (genName in names(newGens)){
304         allMeths=newGens[[genName]]
305         newGens[[genName]] <- allMeths[sapply(allMeths,decide2)]
306          }          }
307          if ( "setMethodS3" == parsed[[on]]@created ){    newGens
308            pattern <- "^([^\\.]+)\\.(.*)$"  
           doc$s3method=c(m1 <- gsub(pattern,"\\1",on,perl=TRUE),  
               m2 <- gsub(pattern,"\\2",on,perl=TRUE))  
           if ( 0 < length(grep("\\W",m1,perl=TRUE)) ){  
             m1 <- paste("`",m1,"`",sep="")  
309            }            }
310            cat("S3method(",m1,",",m2,")\n",sep="")  ############################################################
311    getMethodName <- function(doc.link,e){
312      method.name<- doc.link@name
313      method.name
314          }          }
315    ############################################################
316    getMethodSrc <- function(doc.link,e){
317      chunk.source <- doc.link@code
318      method.name<- doc.link@name
319      old.opt <- options(keep.source=TRUE)
320      parsed <- try(parse(text=chunk.source))
321      options(old.opt)
322      if ( inherits(parsed,"try-error") ){
323        stop("parse failed with error:\n",parsed)
324        }        }
325        if("title" %in% names(doc) && !"description" %in% names(doc) ){    lp <- length(parsed)
326          ## For short functions having both would duplicate, but a    ##pp("lp",environment())
327          ## description is required. Therefore automatically copy title    ##pp("parsed",environment())
328          ## across to avoid errors at package build time.    if(lp!=1){
329          doc$description <- doc$title      stop("extract.docs.setMethod:the expected code should be a lingle setMethod expression")
330        }        }
331        doc  
332    
333      NamedArgs=rewriteSetMethodArgs(parsed[[1]])
334      #pp("NamedArgs",environment())
335      s <- NamedArgs[["signature"]]
336      #pp("s",environment())
337      methodDef=getMethod(
338          f=NamedArgs[["f"]],
339          signature=eval(NamedArgs[["signature"]]),
340          where=e
341        )
342      #pp("methodDef",environment())
343      src=as.character(getSrcref(unRematchDefinition(methodDef)))
344      src
345    }
346     rewriteSetMethodArgs=function(lang){
347       ### Since we do not know if the arguments in the call to setMethod are given with
348       ### keywords, partially matching keywords as an ordered list or any
349       ### combination of it, we use the same function as R  (match.arg )
350       ### to rewrite our argumentlist to a (pair)list from which
351       ### we can extract the information easily
352       KeyWords=c("f","signature","definition","where")
353       NamedArgs=list() # the new argument list
354       args=lang[2:length(lang)]
355       argNames=names(args)
356       if(is.null(argNames)){
357         # in the  special case keyword=value pairs are not given at all
358         # we determine them by position
359         for (i in seq_along(args)){
360            #pp("i",environment())
361            NamedArgs[[KeyWords[[i]] ]] <- args[[i]]
362      }      }
363    extract.docs <- function(on){     }else{
364      res <- try({o <- objs[[on]]       # at least some keyword=value pairs are given
365                  extract.docs.try(o, on)},FALSE)       # we determine them by match arg or by position
366      if(class(res)=="try-error"){       for (i in seq_along(args)){
367        cat("Failed to extract docs for: ",on,"\n\n")          argName=argNames[[i]]
368        list()          if(argNames[[i]]==""){ # no keyword=value given for this arg
369      } else if(0 == length(res) && inherits(objs[[on]],"standardGeneric")){            NamedArgs[[KeyWords[[i]]]] <- args[[i]] #determining the keyword  by position
370        NULL          }else{
371      } else if(0 == length(res) && "function" %in% class(o)           newName=try(match.arg(argNames[[i]],KeyWords))
372                && 1 == length(osource <- attr(o,"source"))           if (class(newName)=="try-error") {
373                && 1 == length(grep(paste("UseMethod(",on,")",sep="\""),osource))             stop(paste("could not match the argument with name : " ,argNames[[i]]," to a formal argument of setMethod",sep=""))
374             }else{
375              NamedArgs[[newName]] <- args[[i]]
376            }
377           }
378         }
379       }
380       #NN <- names(NamedArgs)
381       ##pp("lang",environment())
382       ##pp("args",environment())
383       ##pp("argNames",environment())
384       ##pp("NN",environment())
385       NamedArgs
386     }
387    do.not.generate <- structure(function
388    ### Make a Parser Function used to indicate that certain Rd files
389    ### should not be generated.
390    (...
391    ### Character strings indicating Rd files without the .Rd suffix.
392                ){                ){
393        ## phew - this should only pick up R.oo S3 generic definitions like:    filenames <- c(...)
394        ## attr(*, "source")= chr "function(...) UseMethod(\"select\")"    function(docs,...){
395        NULL      for(fn in filenames){
396      } else res        docs[[fn]] <- list()
397    }    }
398    doc.names <- names(objs)      docs$.overwrite <- TRUE
399    res <- sapply(doc.names,extract.docs,simplify=FALSE)      docs
   ## Special processing for S4 classes as they do not appear in normal ls()  
   for ( nn in names(parsed) ){  
     if ( parsed[[nn]]@created == "setClass" ){  
       S4class.docs <- extract.docs.setClass(parsed[[nn]])  
       docname <- paste(nn,"class",sep="-")  
       if ( is.null(res[[docname]]) ){  
         res[[docname]] <- S4class.docs  
         doc.names <- c(doc.names,docname)  
       } else {  
         stop(nn," appears as both S4 class and some other definition")  
400        }        }
401    ### A Parser Function that will delete items from the outer
402    ### Documentation List.
403    },ex=function(){
404      silly.pkg <- system.file("silly",package="inlinedocs")
405      owd <- setwd(tempdir())
406      file.copy(silly.pkg,".",recursive=TRUE)
407    
408      ## define a custom Parser Function that will not generate some Rd
409      ## files
410      custom <- do.not.generate("silly-package","Silly-class")
411      parsers <- c(default.parsers,list(exclude=custom))
412    
413      ## At first, no Rd files in the man subdirectory.
414      man.dir <- file.path("silly","man")
415      dir(man.dir)
416    
417      ## Running package.skeleton.dx will generate bare-bones files for
418      ## those specified in do.not.generate, if they do not exist.
419      package.skeleton.dx("silly",parsers)
420      Rd.files <- c("silly-package.Rd","Silly-class.Rd","silly.example.Rd")
421      Rd.paths <- file.path(man.dir,Rd.files)
422      stopifnot(all(file.exists(Rd.paths)))
423    
424      ## Save the modification times of the Rd files
425      old <- file.info(Rd.paths)$mtime
426    
427      ## make sure there is at least 2 seconds elapsed, which is the
428      ## resolution for recording times on windows file systems.
429      Sys.sleep(4)
430    
431      ## However, it will NOT generate Rd for files specified in
432      ## do.not.generate, if they DO exist already.
433      package.skeleton.dx("silly",parsers)
434      mtimes <- data.frame(old,new=file.info(Rd.paths)$mtime)
435      rownames(mtimes) <- Rd.files
436      mtimes$changed <- mtimes$old != mtimes$new
437      print(mtimes)
438      stopifnot(mtimes["silly-package.Rd","changed"]==FALSE)
439      stopifnot(mtimes["Silly-class.Rd","changed"]==FALSE)
440      stopifnot(mtimes["silly.example.Rd","changed"]==TRUE)
441    
442      unlink("silly",recursive=TRUE)
443      setwd(owd)
444    })
445    
446    ### combine NULL objects.
447    combine.NULL<-function(x,y){
448        if ((class(x) == "NULL")& (class(y) == "NULL")){
449            # print(paste("mm x=",x))
450            # print(paste("mm class(x)=",class(x)))
451            return(NULL)
452        }
453        if (class(x) == "NULL"){
454            # print(paste("mm x=",x))
455            # print(paste("mm class(x)=",class(x)))
456            x=list("")
457        }
458        if (class(y) == "NULL"){
459            # print(paste("mm y=",y))
460            # print(paste("mm class(y)=",class(y)))
461            y=list("")
462      }      }
463        return(combine(x,y))
464    }    }
465    inherit.docs <- function(on){  
466      in.res <- res[[on]]  ### combine lists or character strings
467      if ( !is.null(parsed[[on]]) ){  combine <- function(x,y){
468        for ( parent in parsed[[on]]@parent ){      UseMethod("combine")
         if ( !is.na(parent) ){  
           if ( is.null(in.res) ){  
             in.res <- res[[parent]]  
           } else if ( parent %in% names(res) ){  
             parent.docs <- res[[parent]]  
             for ( nn in names(parent.docs) ){  
               if ( !nn %in% names(in.res) ){  
                 in.res[[nn]] <- parent.docs[[nn]]  
469                }                }
470    
471    ### combine character strings by pasting them together
472    combine.character <- function(x,y)
473        paste(x,y,sep="\n")
474    
475    ### combine lists by adding elements or adding to existing elements
476    combine.list <- function(x,y){
477      toadd <- if(".overwrite"%in%names(y)){
478        y <- y[names(y)!=".overwrite"]
479        rep(TRUE,length(y))
480      }else{
481        !names(y)%in%names(x)
482              }              }
483      toup <- names(y)[!toadd]
484      x[names(y)[toadd]] <- y[toadd]
485      for(up in toup)x[[up]] <- combine(x[[up]],y[[up]])
486      x
487    ### A list, same type as x, but with added elements from y.
488            }            }
489    
490    
491    getSource <- function
492    ### Extract a function's source code.
493    (fun.obj
494    ### A function.
495     ) {
496          srcref <- attr(fun.obj, "srcref")
497          if (!is.null(srcref)) {
498            ##unlist(strsplit(as.character(srcref), "\n"))
499            as.character(srcref)
500          }          }
501          else attr(fun.obj, "source")
502    ### Source code lines as a character vector.
503        }        }
504    
505    ### Prefix for code comments used with grep and gsub.
506    prefix <- "^[ \t]*###[ \t]*"
507    
508    decomment <- function
509    ### Remove comment prefix and join lines of code to form a
510    ### documentation string.
511    (comments
512    ### Character vector of prefixed comment lines.
513     ){
514      gsub(prefix,"",comments)
515    ### String without prefixes or newlines.
516      }      }
517      invisible(in.res)  
518    forall <- function
519    ### For each object in the package that satisfies the criterion
520    ### checked by subfun, parse source using FUN and return the resulting
521    ### documentation list.
522    (FUN,
523    ### Function to apply to each element in the package.
524     subfun=function(x)TRUE
525    ### Function to select subsets of elements of the package, such as
526    ### is.function. subfun(x)==TRUE means FUN will be applied to x and
527    ### the result will be returned.
528     ){
529      FUN <- FUN
530      f <- function(objs,docs,...){
531        if(length(objs)==0)return(list())
532        objs <- objs[sapply(objs,subfun)]
533        L <- list()
534        on.exit(cat(sprintf("Parser Function failed on %s\n",N)))
535        for(N in union(names(docs),names(objs))){
536          o <- objs[[N]]
537          L[[N]] <- FUN(src=getSource(o),
538                        name=N,objs=objs,o=o,docs=docs,doc=docs[[N]],...)
539    }    }
540    all.done <- FALSE      on.exit()## remove warning message
541    while ( !all.done ){      L
     res1 <- sapply(doc.names,inherit.docs,simplify=FALSE)  
     all.done <- identical(res1,res)  
     res <- res1  
542    }    }
543    ## now strip out any generics (which have value NULL in res):    class(f) <- c("allfun","function")
544    res.not.null <- sapply(res,function(x){!is.null(x)})    f
545    if ( 0 < length(res.not.null) && length(res.not.null) < length(res) ){  ### A Parser Function.
     res <- res[res.not.null]  
546    }    }
547    res  
548  ### named list of lists, one for each object to document.  ### Print method for functions constructed using forall.
549    print.allfun <- function(x,...){
550      e <- environment(x)
551      cat("Function to apply to every element.\nselector:")
552      print(e$subfun)
553      cat("processor:")
554      print(e$FUN)
555  }  }
556    
557  ### List of parsers to use by default with package.skeleton.dx.  ### For each function in the package, do something.
558  default.parsers <- c(extract.docs.file=extract.docs.file,  forfun<- function
559                       sapply(forall.parsers,function(L)L[[1]](L[[2]])))  ### For each object in the package that satisfies the criterion
560    ### checked by subfun, parse source using FUN and return the resulting
561    ### documentation list.
562    (FUN
563    ### Function to apply to each function in the package.
564     ){
565      FUN <- FUN
566      f <- function(objs,docs,...){
567        if(length(objs)==0)return(list())
568        objs <- objs[sapply(objs,is.function)]
569        L <- list()
570        on.exit(cat(sprintf("Parser Function failed on %s\n",N)))
571        for(N in names(objs)){
572          o <- objs[[N]]
573          L[[N]] <- FUN(src=getSource(o),
574                        name=N,objs=objs,o=o,docs=docs,doc=docs[[N]],...)
575        }
576        on.exit()## remove warning message
577        L
578      }
579      class(f) <- c("allfun","function")
580      f
581    ### A Parser Function.
582    }
583    
584  extract.docs.fun <- function # Extract documentation from a function  kill.prefix.whitespace <- function
585  ### Given source code of a function, return a list describing inline  ### Figure out what the whitespace preceding the example code is, and
586  ### documentation in that source code.  ### then delete that from every line.
587  (code,  (ex
588  ### The function to examine.  ### character vector of example code lines.
  name.fun  
 ### The name of the function/chunk to use in warning messages.  
589   ){   ){
590    res <- list()    tlines <- gsub("\\s*","",ex)
591    clines <- grep(prefix,code)    ##tlines <- gsub("#.*","",tlines)
592    if(length(grep("#",code[1]))){    prefixes <- unique(gsub("\\S.*","",ex[tlines!=""]))
593      res$title <- gsub("[^#]*#\\s*(.*)","\\1",code[1],perl=TRUE)    FIND <- prefixes[which.min(nchar(prefixes))]
594      ## Eliminate leading tabulations or 2/4 spaces
595      sub(FIND, "", ex)
596    ### Character vector of code lines with preceding whitespace removed.
597    }    }
598    if(length(clines) > 0){  
599      ##details<<  prefixed.lines <- structure(function(src,...){
600      ## The primary mechanism is that consecutive groups of lines matching  ### The primary mechanism of inline documentation is via consecutive
601      ## the specified prefix regular expression "\code{^### }" (i.e. lines  ### groups of lines matching the specified prefix regular expression
602      ## beginning with "\code{### }") are collected  ### "\code{^### }" (i.e. lines beginning with "\code{### }") are
603      ## as follows into documentation sections:\describe{  ### collected as follows into documentation sections:\describe{
604      ## \item{description}{group starting at line 2 in the code}  ### \item{description}{group starting at line 2 in the code}
605      ## \item{arguments}{group following each function argument}  ### \item{arguments}{group following each function argument}
606      ## \item{value}{group ending at the penultimate line of the code}}  ### \item{value}{group ending at the penultimate line of the code}}
607      ## These may be added to by use of the \code{##<<} constructs described  ### These may be added to by use of the \code{##<<} constructs
608      ## below.  ### described below.
609      clines <- grep(prefix,src)
610      if(length(clines)==0)return(list())
611      bounds <- which(diff(clines)!=1)      bounds <- which(diff(clines)!=1)
612      starts <- c(1,bounds+1)      starts <- c(1,bounds+1)
613      ends <- c(bounds,length(clines))      ends <- c(bounds,length(clines))
614      ## detect body of function using paren matching
615      code <- gsub("#.*","",src)
616      f <- function(ch)cumsum(nchar(gsub(sprintf("[^%s]",ch),"",code)))
617      parens <- f("(")-f(")")
618      body.begin <- which(diff(parens)<0 & parens[-1]==0)+2
619      if(length(body.begin)==0)body.begin <- 1 ## rare cases
620      is.arg <- function(){
621        gres <- grep("^\\s*#",src[start-1],perl=TRUE)
622        0 == length(gres) && start<=body.begin
623      }
624      res <- list()
625      for(i in seq_along(starts)){      for(i in seq_along(starts)){
626        start <- clines[starts[i]]        start <- clines[starts[i]]
627        end <- clines[ends[i]]        end <- clines[ends[i]]
628        lab <- if(end+1==length(code))"value"      processed <- gsub("#.*","",gsub("[ }]","",src[(end+1):length(src)]))
629        lab <- if(all(processed==""))"value"
630        else if(start==2)"description"        else if(start==2)"description"
631        else if ( 0 == length(grep("^\\s*#",code[start-1],perl=TRUE)) ){      else if(is.arg()){
632           #arg <- gsub("^[ (]*","",code[start-1])        ##twutz: strip leading white spaces and brackets and ,
633           #arg <- gsub("^([^=,]*)[=,].*","\\1",arg)        arg <- gsub("^[ \t(,]*", "", src[start - 1])
          #arg <- gsub("...","\\dots",arg,fix=TRUE) ##special case for dots  
                  arg <- gsub("^[ \t(,]*", "", code[start - 1])  #twutz: strip leading white spaces and brackets and ,  
634                   arg <- gsub("^([^=,]*)[=,].*", "\\1", arg)                   arg <- gsub("^([^=,]*)[=,].*", "\\1", arg)
635                   arg <- gsub("^([^ \t]*)([ \t]+)$","\\1",arg)   #twutz: remove trailing whitespaces        ##twutz: remove trailing whitespaces
636                   arg <- gsub("...", "\\dots", arg, fix = TRUE)        arg <- gsub("^([^ \t]*)([ \t]+)$","\\1",arg)
637          arg <- gsub("...", "\\dots", arg, fixed = TRUE)
638           paste("item{",arg,"}",sep="")           paste("item{",arg,"}",sep="")
639         } else {         } else {
640           next;           next;
641         }         }
642        res[[lab]] <- decomment(code[start:end])      res[[lab]] <- decomment(src[start:end])
     }  
643    }    }
644      res
645    },ex=function(){
646    test <- function
647    ### the description
648    (x,
649    ### the first argument
650     y ##<< another argument
651     ){
652      5
653    ### the return value
654    ##seealso<< foobar
655    }
656    src <- getSource(test)
657    prefixed.lines(src)
658    extract.xxx.chunks(src)
659    })
660    
661    extract.xxx.chunks <- function # Extract documentation from a function
662    ### Given source code of a function, return a list describing inline
663    ### documentation in that source code.
664    (src,
665    ### The source lines of the function to examine, as a character
666    ### vector.
667     name.fun="(unnamed function)",
668    ### The name of the function/chunk to use in warning messages.
669     ...
670    ### ignored.
671     ){
672      res <- list()
673    ##details<< For simple functions/arguments, the argument may also be    ##details<< For simple functions/arguments, the argument may also be
674    ## documented by appending \code{##<<} comments on the same line as the    ## documented by appending \code{##<<} comments on the same line as the
675    ## argument name. Mixing this mechanism with \code{###} comment lines for    ## argument name. Mixing this mechanism with \code{###} comment lines for
# Line 318  Line 742 
742          chunk.sep <- "\n\n"          chunk.sep <- "\n\n"
743        }        }
744        chunk.res <- NULL        chunk.res <- NULL
745        if ( 0 == length(grep("^\\s*$",payload,perl=TRUE)) )        if ( !grepl("^\\s*$",payload,perl=TRUE) )
746          chunk.res <-          chunk.res <-
747            if ( is.null(res[[field]]) ) payload            if ( is.null(res[[field]]) ) payload
748            else paste(res[[field]], payload, sep=chunk.sep)            else paste(res[[field]], payload, sep=chunk.sep)
749        invisible(chunk.res)        invisible(chunk.res)
750      }      }
751    while ( k <= length(code) ){    while ( k <= length(src) ){
752      line <- code[k]      line <- src[k]
753      if ( 0 < length(grep(extra.regexp,line,perl=TRUE) ) ){      ##print(line)
754        ##if(grepl("^$",line))browser()
755        if ( grepl(extra.regexp,line,perl=TRUE) ){
756        ## we have a new extra chunk - first get field name and any payload        ## we have a new extra chunk - first get field name and any payload
757        new.field <- gsub(extra.regexp,"\\1",line,perl=TRUE)        new.field <- gsub(extra.regexp,"\\1",line,perl=TRUE)
758        new.contents <- gsub(extra.regexp,"\\2",line,perl=TRUE)        new.contents <- gsub(extra.regexp,"\\2",line,perl=TRUE)
759          ##cat(new.field,"\n-----\n",new.contents,"\n\n")
760        ##details<< As a special case, the construct \code{##describe<<} causes        ##details<< As a special case, the construct \code{##describe<<} causes
761        ## similar processing to the main function arguments to be        ## similar processing to the main function arguments to be
762        ## applied in order to construct a describe block within the        ## applied in order to construct a describe block within the
# Line 339  Line 765 
765        ## block until terminated by a subsequent \code{##}\emph{xxx}\code{<<} line.        ## block until terminated by a subsequent \code{##}\emph{xxx}\code{<<} line.
766        if ( "describe" == new.field ){        if ( "describe" == new.field ){
767          ##details<< Such regions may be nested, but not in such a way          ##details<< Such regions may be nested, but not in such a way
768          ## that the first element in a \code{describe} is another \code{describe}.          ## that the first element in a \code{describe} is another
769          ## Thus there must be at least one \code{##<<} comment between each          ## \code{describe}.  Thus there must be at least one
770          ## pair of \code{##describe<<} comments.          ## \code{##<<} comment between each pair of
771            ## \code{##describe<<} comments.
772          if ( first.describe ){          if ( first.describe ){
773            stop("consecutive ##describe<< at line",k,"in",name.fun)            stop("consecutive ##describe<< at line",k,"in",name.fun)
774          } else {          } else {
# Line 401  Line 828 
828            first.describe <- TRUE;            first.describe <- TRUE;
829          }          }
830        }        }
831      } else if ( in.chunk && 0<length(grep(cont.re,line,perl=TRUE)) ){      } else if ( in.chunk && grepl(cont.re,line,perl=TRUE) ){
832        ## append this line to current chunk        ## append this line to current chunk
833        if ( 0 == length(grep(prefix,line,perl=TRUE)) ){        if ( !grepl(prefix,line,perl=TRUE) ){
834          ##describe<< Any lines with "\code{### }" at the left hand          ##describe<< Any lines with "\code{### }" at the left hand
835          ## margin within the included chunks are handled separately,          ## margin within the included chunks are handled separately,
836          ## so if they appear in the documentation they will appear          ## so if they appear in the documentation they will appear
# Line 416  Line 843 
843            payload <- stripped            payload <- stripped
844          }          }
845        }        }
846      } else if ( 0 < length(grep(arg.pat,line,perl=TRUE)) ){      } else if ( grepl(arg.pat,line,perl=TRUE) ){
847        not.describe <- (0==in.describe && !first.describe)        not.describe <- (0==in.describe && !first.describe)
848        if ( in.chunk && not.describe){        if ( in.chunk && not.describe){
849          res[[cur.field]] <- end.chunk(cur.field,payload)          res[[cur.field]] <- end.chunk(cur.field,payload)
# Line 425  Line 852 
852        arg <- gsub(arg.pat,"\\\\item\\{\\1\\}",line,perl=TRUE)        arg <- gsub(arg.pat,"\\\\item\\{\\1\\}",line,perl=TRUE)
853        in.chunk <- TRUE        in.chunk <- TRUE
854        if ( not.describe ){        if ( not.describe ){
855          cur.field <- gsub("...","\\dots",arg,fix=TRUE) ##special case for dots          ## TDH 2010-06-18 For item{}s in the documentation list names,
856            ## we don't need to have a backslash before, so delete it.
857            arg <- gsub("^[\\]+","",arg)
858            cur.field <- gsub("...","\\dots",arg,fixed=TRUE) ##special case for dots
859          payload <- comment          payload <- comment
860        } else {        } else {
861          ## 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 475  Line 905 
905  ### with the string in this list (implemented in modify.Rd.file).  ### with the string in this list (implemented in modify.Rd.file).
906  }  }
907    
908    leadingS3generic <- function # check whether function name is an S3 generic
909    ### Determines whether a function name looks like an S3 generic function
910    (name,                     ##<< name of function
911     env,                      ##<< environment to search for additional generics
912     ...)                      ##<< ignored here
913    {
914      ##details<< This function is one of the default parsers, but exposed as
915      ## possibly of more general interest. Given a function name of the form
916      ## x.y.z it looks for the generic function x applying to objects of class
917      ## y.z and also for generic function x.y applying to objects of class z.
918      ##
919      parts <- strsplit(name, ".", fixed = TRUE)[[1]]
920      l <- length(parts)
921      if (l > 1) {
922        for (i in 1:(l - 1)) {
923          ## Look for a generic function (known by the system or defined
924          ## in the package) that matches that part of the function name
925          generic <- paste(parts[1:i], collapse = ".")
926          if (any(generic %in% getKnownS3generics()) ||
927              findGeneric(generic, env) != "") {
928            object <- paste(parts[(i + 1):l], collapse = ".")
929            ##details<< Assumes that the first name which matches any known
930            ## generics is the target generic function, so if both x and x.y
931            ## are generic functions, will assume generic x applying to objects
932            ## of class y.z
933            ##value<< If a matching generic found returns a list with a single component:
934            return(list(.s3method=c(generic, object))) ##<< a character vector containing generic name and object name.
935          }
936        }
937      }
938      ##value<< If no matching generic functions are found, returns an empty list.
939      list()
940    }
941    
942    definition.from.source=function(doc,src,...)
943    ### small helper to extract the definition of a doc entry from a bit of src code
944    {
945      def <- doc$definition
946      is.empty <- function(x)is.null(x)||x==""
947      if(is.empty(def) && !is.empty(src))
948        list(definition=src)
949      else list()
950    }
951    ## title from first line of function def
952    title.from.firstline=function
953    ### extract the title from the first line of a function definition
954    (src,...){
955      first <- src[1]
956      if(!is.character(first))return(list())
957      if(!grepl("#",first))return(list())
958      list(title=gsub("[^#]*#\\s*(.*)","\\1",first,perl=TRUE))
959    }
960    ############
961    mm.examples.from.testfile=function
962    ### extract examples from external files
963    (name,inlinedocs.exampleDir,inlinedocs.exampleTrunk,...){
964      tsubdir <-inlinedocs.exampleDir
965      trunk<- inlinedocs.exampleTrunk
966      if (is.null(tsubdir)) {
967        return(list())# do nothing
968      }
969      p <- paste(trunk,name,".R",sep="")
970      allfiles=dir(tsubdir)
971      L<- allfiles[grepl(pattern=p,allfiles,fixed=TRUE)]
972      path=function(l){file.path(tsubdir,l)}
973      paths=lapply(L,path)
974      print(lapply(paths,file.exists))
975    
976      res=list()
977      if(length(L)>0){
978        exampleTexts= lapply(paths,readLines)
979        combinedText <- unlist(exampleTexts)
980        res[["examples"]]=combinedText
981        ##pp("res",environment())
982    
983      }
984      res
985    }
986    ### Parsers for each function that are constructed automatically. This
987    ### is a named list, and each element is a parser function for an
988    ### individual object.
989    forfun.parsers <-
990      list(prefixed.lines=prefixed.lines,
991           extract.xxx.chunks=extract.xxx.chunks,
992           title.from.firstline=title.from.firstline,
993           ## PhG: it is tests/FUN.R!!! I would like more flexibility here
994           ## please, let me choose which dir to use for examples!
995           ## Get examples for FUN from the file tests/FUN.R
996           examples.from.testfile=function(name,...){
997             tsubdir <- getOption("inlinedocs.exdir")
998             if (is.null(tsubdir)) tsubdir <- "tests"       # Default value
999             tfile <- file.path("..",tsubdir,paste(name,".R",sep=""))
1000             print(file.exists(tfile))
1001             if(file.exists(tfile)){
1002               list(examples=readLines(tfile))
1003             }
1004             else list()
1005           },
1006           mm.examples.from.testfile=mm.examples.from.testfile,
1007           definition.from.source=definition.from.source
1008           )
1009    
1010    extract.docs<-function
1011    ### produce doc link instances
1012    (parsed,objs,on){
1013      ##pp("on",environment())
1014      extract.docs.try <-function(o,on)
1015        {
1016          ## Note: we could use parsed information here too, but that
1017          ## would produce different results for R.methodsS3::setMethodS3 etc.
1018          doc <- list()
1019          if ( !is.null(parsed[[on]]) ){
1020            if ( !is.na(parsed[[on]]@code[1]) ){ # no code given for generics
1021              doc$definition <- paste(parsed[[on]]@code)
1022            }
1023            if(!"description"%in%names(doc) && !is.na(parsed[[on]]@description) ){
1024              doc$description <- parsed[[on]]@description
1025            }
1026            ## if ( "R.methodsS3::setMethodS3" == parsed[[on]]@created ){
1027            ##   gen <- leadingS3generic(on,topenv())
1028            ##   if ( 0 < length(gen) ){
1029            ##     doc$.s3method <- gen$.s3method
1030            ##     cat("S3method(",gen$.s3method[1],",",gen$.s3method[2],")\n",sep="")
1031            ##   }
1032            ## }
1033          }
1034          if("title" %in% names(doc) && !"description" %in% names(doc) ){
1035            ## For short functions having both would duplicate, but a
1036            ## description is required. Therefore automatically copy title
1037            ## across to avoid errors at package build time.
1038            doc$description <- doc$title
1039          }
1040          doc
1041        }
1042        res <- try({o <- objs[[on]]
1043                    extract.docs.try(o, on)},FALSE)
1044        if(class(res)=="try-error"){
1045          cat("Failed to extract docs for: ",on,"\n\n")
1046          list()
1047        } else if(0 == length(res) && inherits(objs[[on]],"standardGeneric")){
1048          NULL
1049        } else if(0 == length(res) && "function" %in% class(o)
1050                  && 1 == length(osource <- getSource(o))
1051                  && grepl(paste("UseMethod(",on,")",sep="\""),osource)
1052                  ){
1053          ## phew - this should only pick up R.oo S3 generic definitions like:
1054          ## attr(*, "source")= chr "function(...) UseMethod(\"select\")"
1055          NULL
1056        } else res
1057      }
1058    
1059    inherit.docs <- function(
1060    ### recursively add documentation inherited from doc.link parents
1061      parsed, ##<< a list of doc.link objects
1062      res,    ##<< the list of documentation to be extended
1063      childName      ##<< the name of the object who possibly inherits
1064      ){
1065      in.res <- res[[childName]] #start with the present
1066      ##pp("in.res",environment())
1067      childsDocLink <-parsed[[childName]]
1068      if ( !is.null(childsDocLink) ){
1069        for ( parent in childsDocLink@parent ){
1070          if ( !is.na(parent) ){
1071            ##pp("parent",environment())
1072            #pe(quote(names(res)),environment())
1073            #pe(quote(parent %in% names(res)),environment())
1074            if ( is.null(in.res) ){
1075              in.res <- res[[parent]]
1076            } else if ( parent %in% names(res) ){
1077              parent.docs <- res[[parent]]
1078              for ( nn in names(parent.docs) ){
1079                if ( !nn %in% names(in.res) ){
1080                  in.res[[nn]] <- parent.docs[[nn]]
1081                }
1082              }
1083          }
1084        }
1085        }
1086      }
1087      invisible(in.res)
1088      ### the possibly extended list of documentation
1089    }
1090    
1091    
1092    extra.method.docs <- function
1093    ### can be used in the parser list of package.skeleton.dx(). TODO:
1094    (code,
1095    ### Code lines in a character vector containing multiple R objects to
1096    ### parse for documentation.
1097    objs,
1098    ### The objects defined in the code.
1099    env,
1100    ### The environment they inhibit (needed to pass on)
1101    inlinedocs.exampleDir,
1102    ### A string pointing to the location where inlinedocs should search for external examples
1103    inlinedocs.exampleTrunk,
1104    ### A string used to identify the files containing external examples in the example directory. All file names of external examples have to start with this string
1105    ...
1106    ### ignored
1107     ){
1108      doc.names <- names(objs)
1109      parsed <- extract.file.parse(code,env)
1110      res=list()
1111      for ( nn in names(parsed) ){
1112        dL=parsed[[nn]]
1113        if ( dL@created == "setMethod" ){
1114          S4Method.docs <- extract.docs.setMethod(dL,env,inlinedocs.exampleDir,inlinedocs.exampleTrunk)
1115          docname <- dL@name
1116          if ( is.null(res[[docname]]) ){
1117            res[[docname]] <- S4Method.docs
1118            doc.names <- c(doc.names,docname)
1119          } else {
1120            stop(nn," appears as both S4 method and some other definition")
1121          }
1122        }
1123      }
1124      all.done <- FALSE
1125      while ( !all.done ){
1126        res1 <- sapply(doc.names,inherit.docs,parsed=parsed,res=res,simplify=FALSE)
1127        all.done <- identical(res1,res)
1128        res <- res1
1129      }
1130      res
1131    ### named list of lists, one for each object to document.
1132    }
1133    
1134    
1135    
1136    extra.class.docs <- function # Extract documentation from code chunks
1137    ### Parse R code to extract inline documentation from comments around
1138    ### each class
1139    ### looking at the "source" attribute. This is a Parser Function that
1140    ### can be used in the parser list of package.skeleton.dx(). TODO:
1141    (code,
1142    ### Code lines in a character vector containing multiple R objects to
1143    ### parse for documentation.
1144    objs,
1145    ### The objects defined in the code.
1146    env,
1147    ### The environment they inhibit (needed to pass on)
1148    ...
1149    ### ignored
1150     ){
1151      doc.names <- names(objs)
1152      parsed <- extract.file.parse(code,env)
1153      res=list()
1154      for ( nn in names(parsed) ){
1155        if ( parsed[[nn]]@created == "setClass" ){
1156          S4class.docs <- extract.docs.setClass(parsed[[nn]])
1157          docname <- paste(nn,"class",sep="-")
1158          if ( is.null(res[[docname]]) ){
1159            res[[docname]] <- S4class.docs
1160            doc.names <- c(doc.names,docname)
1161          } else {
1162            stop(nn," appears as both S4 class and some other definition")
1163          }
1164        }
1165      }
1166      all.done <- FALSE
1167      while ( !all.done ){
1168        res1 <- sapply(doc.names,inherit.docs,parsed=parsed,res=res,simplify=FALSE)
1169        all.done <- identical(res1,res)
1170        res <- res1
1171      }
1172      res
1173    ### named list of lists, one for each object to document.
1174    }
1175    extra.code.docs <- function # Extract documentation from code chunks
1176    ### Parse R code to extract inline documentation from comments around
1177    ### each function. These are not able to be retreived simply by
1178    ### looking at the "source" attribute. This is a Parser Function that
1179    ### can be used in the parser list of package.skeleton.dx(). TODO:
1180    ### Modularize this into separate Parsers Functions for S4 classes,
1181    ### prefixes, ##<<blocks, etc. Right now it is not very clean!
1182    (code,
1183    ### Code lines in a character vector containing multiple R objects to
1184    ### parse for documentation.
1185     objs,
1186    ### The objects defined in the code.
1187    env, # the environment
1188     ...
1189    ### ignored
1190     ){
1191      parsed <- extract.file.parse(code,env)
1192      doc.names <- names(objs)
1193      res <- sapply(doc.names,extract.docs,parsed=parsed,objs=objs,simplify=FALSE)
1194      all.done <- FALSE
1195      while ( !all.done ){
1196        res1 <- sapply(doc.names,inherit.docs,parsed=parsed,res=res,simplify=FALSE)
1197        all.done <- identical(res1,res)
1198        res <- res1
1199      }
1200      ## now strip out any generics (which have value NULL in res):
1201      res.not.null <- sapply(res,function(x){!is.null(x)})
1202      if ( 0 < length(res.not.null) && length(res.not.null) < length(res) ){
1203        res <- res[res.not.null]
1204      }
1205      res
1206    ### named list of lists, one for each object to document.
1207    }
1208    ### List of Parser Functions that can be applied to any object.
1209    forall.parsers <-
1210      list(## Fill in author from DESCRIPTION and titles.
1211           author.from.description=function(desc,...){
1212             list(author=desc[,"Author"])
1213           },
1214           ## The format section sometimes causes problems, so erase it.
1215           erase.format=function(...){
1216             list(format="")
1217           },
1218           ## Convert the function name to a title.
1219           title.from.name=function(name,doc,...){
1220             if("title"%in%names(doc))list() else
1221             list(title=gsub("[._]"," ",name))
1222           },
1223           ## PhG: here is what I propose for examples code in the 'ex' attribute
1224           examples.in.attr =  function (name, o, ...) {
1225             ex <- attr(o, "ex",exact=TRUE)
1226             if (!is.null(ex)) {
1227               ## Special case for code contained in a function
1228               if (inherits(ex, "function")) {
1229                 ## If source is available, start from there
1230                 src <- getSource(ex)
1231                 if (!is.null(src)) {
1232                   ex <- src
1233                 } else { ## Use the body of the function
1234                   ex <- deparse(body(ex))
1235                 }
1236                 ## Eliminate leading and trailing code
1237                 ex <- ex[-c(1, length(ex))]
1238                 if( length(ex) ){  # avoid error on yet empty example
1239                     if(ex[1]=="{")ex <- ex[-1]
1240                     ## all the prefixes
1241                     ex <- kill.prefix.whitespace(ex)
1242                 }
1243                 ## Add an empty line before and after example
1244                 ex <- c("", ex, "")
1245               }
1246               list(examples = ex)
1247             } else list()
1248           },collapse=function(doc,...){
1249             L <- lapply(doc,paste,collapse="\n")
1250             L$.overwrite <- TRUE
1251             L
1252           },tag.s3methods=leadingS3generic
1253           )
1254    
1255    ### List of parser functions that operate on single objects. This list
1256    ### is useful for testing these functions.
1257    lonely <- structure(c(forall.parsers,forfun.parsers),ex=function(){
1258      f <- function # title
1259    ### description
1260      (x, ##<< arg x
1261       y
1262    ### arg y
1263       ){
1264        ##value<< a list with elements
1265        list(x=x, ##<< original x value
1266             y=y, ##<< original y value
1267             sum=x+y) ##<< their sum
1268        ##end<<
1269      }
1270      src <- getSource(f)
1271      lonely$extract.xxx.chunks(src)
1272      lonely$prefixed.lines(src)
1273    })
1274    
1275    
1276    ### List of parsers to use by default with package.skeleton.dx.
1277    default.parsers <-
1278      c(
1279        extra.class.docs=extra.class.docs, ## TODO: cleanup!
1280        extra.method.docs=extra.method.docs, ## TODO: cleanup!
1281        extra.code.docs=extra.code.docs, ## TODO: cleanup!
1282        sapply(forfun.parsers,forfun),
1283        edit.package.file=function(desc,...){
1284          in.details <- setdiff(colnames(desc),"Description")
1285          details <- sprintf("%s: \\tab %s\\cr",in.details,desc[,in.details])
1286          L <-
1287            list(list(title=desc[,"Title"],
1288                      description=desc[,"Description"],
1289                      `tabular{ll}`=details))
1290          names(L) <- paste(desc[,"Package"],"-package",sep="")
1291          L
1292        },
1293        sapply(forall.parsers,forall)
1294        )
1295    
1296  setClass("DocLink", # Link documentation among related functions  setClass("DocLink", # Link documentation among related functions
1297  ### The \code{.DocLink} class provides the basis for hooking together  ### The \code{.DocLink} class provides the basis for hooking together
1298  ### documentation of related classes/functions/objects. The aim is that  ### documentation of related classes/functions/objects. The aim is that
1299  ### documentation sections missing from the child are  ### documentation sections missing from the child are inherited from
1300    ### the parent class.
1301           representation(name="character", ##<< name of object           representation(name="character", ##<< name of object
1302                          created="character", ##<< how created                          created="character", ##<< how created
1303                          parent="character", ##<< parent class or NA                          parent="character", ##<< parent class or NA
# Line 487  Line 1306 
1306           )           )
1307    
1308  extract.file.parse <- function # File content analysis  extract.file.parse <- function # File content analysis
1309  ### Using the base \code{\link{parse}} function, analyse the file to link  ### Using the base \code{parse} function, analyse the file to link
1310  ### preceding "prefix" comments to each active chunk. Those comments form  ### preceding "prefix" comments to each active chunk. Those comments form
1311  ### the default description for that chunk. The analysis also looks for  ### the default description for that chunk. The analysis also looks for
1312  ### S4 class "setClass" calls and R.oo setConstructorS3 and setMethodS3  ### S4 class "setClass" ,R.oo setConstructorS3  R.methodsS3::setMethodS3
1313  ### calls in order to link the documentation of those properly.  ### or S4 setMethod calls in order to link the documentation of those properly.
1314  (code  (code,
1315  ### Lines of R source code in a character vector - note that any  ### Lines of R source code in a character vector - note that any
1316  ### nested \code{source} statements are \emph{ignored} when scanning  ### nested \code{source} statements are \emph{ignored} when scanning
1317  ### for class definitions.  ### for class definitions.
1318     env
1319     ### the environment in which the code has been evaluated before.
1320     ### This is e.g. iportant to make sure that we can evaluate expressions
1321     ### like signature definitions for methods
1322   ){   ){
1323    res <- list()    res <- list()
1324    old.opt <- options(keep.source=TRUE)    old.opt <- options(keep.source=TRUE)
# Line 513  Line 1336 
1336      ## "prefix" lines will be used instead.      ## "prefix" lines will be used instead.
1337      default.description <- NULL      default.description <- NULL
1338      while ( start > last.end+1      while ( start > last.end+1
1339             && 1 == length(grep(prefix,code[start-1],perl=TRUE)) ){             && grepl(prefix,code[start-1],perl=TRUE) ){
1340        start <- start-1        start <- start-1
1341      }      }
1342      if ( start < chunks[[k]][1] ){      if ( start < chunks[[k]][1] ){
# Line 525  Line 1348 
1348      ## determined by expression type: \describe{      ## determined by expression type: \describe{
1349      ## \item{assignment (<-)}{Ordinary assignment of value/function;}      ## \item{assignment (<-)}{Ordinary assignment of value/function;}
1350      ## \item{setClass}{Definition of S4 class;}      ## \item{setClass}{Definition of S4 class;}
1351        ## \item{setMethod}{Definition of a method of a S4 generic;}
1352      ## \item{setConstructorS3}{Definition of S3 class using R.oo package;}      ## \item{setConstructorS3}{Definition of S3 class using R.oo package;}
1353      ## \item{setMethodS3}{Definition of method for S3 class using R.oo package.}}      ## \item{R.methodsS3::setMethodS3}{Definition of method for S3 class using R.oo package.}}
1354      ## Additionally, the value may be a name of a function defined elsewhere,      ## Additionally, the value may be a name of a function defined elsewhere,
1355      ## in which case the documentation should be copied from that other definition.      ## in which case the documentation should be copied from that other definition.
1356      ## This is handled using the concept of documentation links.      ## This is handled using the concept of documentation links.
# Line 535  Line 1359 
1359      expr.type <- chars[1]      expr.type <- chars[1]
1360      parent <- NA_character_      parent <- NA_character_
1361    
1362      if ( expr.type == "<-" || expr.type == "setConstructorS3" || expr.type == "setClass" ){      if ( expr.type == "<-" || expr.type == "setConstructorS3" ){
1363        object.name <- chars[2]        object.name <- chars[2]
1364        ## If the function definition is not embedded within the call, then        ## If the function definition is not embedded within the call, then
1365        ## the parent is that function. Test whether the the third value        ## the parent is that function. Test whether the the third value
1366        ## looks like a name and add it to parents if so.        ## looks like a name and add it to parents if so.
1367        if ( 1 == length(grep("^[\\._\\w]+$",chars[3],perl=TRUE)) ){        if ( grepl("^[\\._\\w]+$",chars[3],perl=TRUE) ){
1368          parent <- chars[3]          parent <- chars[3]
1369        }        }
1370        res[[object.name]] <- new("DocLink",name=object.name,        res[[object.name]] <- new("DocLink",name=object.name,
# Line 548  Line 1372 
1372                                  parent=parent,                                  parent=parent,
1373                                  code=paste(chunks[[k]],sep=""),                                  code=paste(chunks[[k]],sep=""),
1374                                  description=default.description)                                  description=default.description)
1375      } else if ( expr.type == "setMethodS3" ){      } else if ( expr.type == "setClass" ){
1376        ##details<< The \code{setMethodS3} calls introduce additional        object.name <- chars[2]
1377          res[[object.name]] <- new("DocLink",name=object.name,
1378                                    created=expr.type,
1379                                    parent=parent,
1380                                    code=paste(chunks[[k]],sep=""),
1381                                    description=default.description)
1382    
1383        }
1384        else if ( expr.type == "R.methodsS3::setMethodS3" || expr.type ==  "R.methodsS3::R.methodsS3::setMethodS3"){
1385          ##details<< The \code{R.methodsS3::setMethodS3} calls introduce additional
1386        ## complexity: they will define an additional S3 generic (which        ## complexity: they will define an additional S3 generic (which
1387        ## needs documentation to avoid warnings at package build time)        ## needs documentation to avoid warnings at package build time)
1388        ## unless one already exists. This also is handled by "linking"        ## unless one already exists. This also is handled by "linking"
1389        ## documentation. A previously unseen generic is linked to the        ## documentation. A previously unseen S3generic is linked to the
1390        ## first defining instances, subsequent definitions of that generic        ## first defining instances, subsequent definitions of that S3generic
1391        ## also link back to the first defining instance.        ## also link back to the first defining instance.
1392        generic.name <- chars[2]        S3generic.name <- chars[2]
1393        object.name <- paste(generic.name,chars[3],sep=".")        object.name <- paste(S3generic.name,chars[3],sep=".")
1394        if ( is.null(res[[generic.name]]) ){        if ( is.null(res[[S3generic.name]]) ){
1395          generic.desc <- paste("Generic method behind \\code{\\link{",object.name,"}}",sep="")          ## TDH 9 April 2012 Do NOT add \\link in S3generic.desc below,
1396          res[[generic.name]] <- new("DocLink",          ## since it causes problems on R CMD check.
1397                                     name=generic.name,          ##* checking Rd cross-references ... WARNING
1398            ##Error in find.package(package, lib.loc) :
1399            ##  there is no package called ‘MASS’
1400            ##Calls: <Anonymous> -> lapply -> FUN -> find.package
1401    
1402            S3generic.desc <-
1403              paste("Generic method behind \\code{",object.name,"}",sep="")
1404            res[[S3generic.name]] <- new("DocLink",
1405                                       name=S3generic.name,
1406                                     created=expr.type,                                     created=expr.type,
1407                                     parent=object.name,                                     parent=object.name,
1408                                     code=NA_character_,                                     code=NA_character_,
1409                                     description=generic.desc)                                     description=S3generic.desc)
1410        } else {        } else {
1411          parent <- res[[generic.name]]@parent          parent <- res[[S3generic.name]]@parent
1412        }        }
1413        ## If the function definition is not embedded within the call, then        ## If the function definition is not embedded within the call, then
1414        ## the parent is that function. Test whether the the fourth value        ## the parent is that function. Test whether the the fourth value
1415        ## looks like a name and add it to parents if so.        ## looks like a name and add it to parents if so.
1416        if ( 1 == length(grep("^[\\._\\w]+$",chars[4],perl=TRUE)) ){        if ( grepl("^[\\._\\w]+$",chars[4],perl=TRUE) ){
1417          parent <- c(chars[4],parent)          parent <- c(chars[4],parent)
1418        }        }
1419        res[[object.name]] <- new("DocLink",name=object.name,        res[[object.name]] <- new("DocLink",name=object.name,
# Line 580  Line 1421 
1421                                  parent=parent,                                  parent=parent,
1422                                  code=paste(chunks[[k]],sep=""),                                  code=paste(chunks[[k]],sep=""),
1423                                  description=default.description)                                  description=default.description)
1424        } else if (expr.type == "setMethod" ) {
1425    
1426          NamedArgs=rewriteSetMethodArgs(lang)
1427          genName=NamedArgs[["f"]]
1428          sigexp=NamedArgs[["signature"]]
1429          sig=eval(sigexp,env)
1430          N <- methodDocName(genName,sig)
1431          object.name <- N
1432    
1433          ## If the function definition is not embedded within the call, then
1434          ## the parent is that function. Test whether the value for "definition"
1435          ## looks like a funktion name and add it to parents if so.
1436          def=paste(as.character(NamedArgs[["definition"]]),collapse="\n")
1437          if ( grepl("^[\\._\\w]+$",def,perl=TRUE) ){
1438            parent <- def
1439          }
1440          res[[object.name]] <- new("DocLink",name=object.name,
1441                                    created=expr.type,
1442                                    parent=parent,
1443                                    code=paste(chunks[[k]],sep=""),
1444                                    description=default.description)
1445      } else {      } else {
1446        ## Not sure what to do with these yet. Need to deal with setMethod, setAs etc.        ## Not sure what to do with these yet. Need to deal with setAs etc.
1447      }      }
1448    }    }
1449    invisible(res)    invisible(res)
# Line 593  Line 1455 
1455  ### in the form \code{setClass("classname",\dots)} are also located and  ### in the form \code{setClass("classname",\dots)} are also located and
1456  ### scanned for inline comments.  ### scanned for inline comments.
1457  (doc.link  (doc.link
1458  ### DocLink object as created by \code{\link{extract.file.parse}}.  ### DocLink object as created by \code{extract.file.parse}.
1459  ### Note that \code{source} statements are \emph{ignored} when scanning for  ### Note that \code{source} statements are \emph{ignored} when scanning for
1460  ### class definitions.  ### class definitions.
1461   ){   ){
# Line 613  Line 1475 
1475    ## the same line or \code{### } comments at the beginning of the    ## the same line or \code{### } comments at the beginning of the
1476    ## following line.    ## following line.
1477    f.n <- paste(class.name,"class",sep="-")    f.n <- paste(class.name,"class",sep="-")
1478    docs <- extract.docs.fun(chunk.source,f.n)    docs <- extract.xxx.chunks(chunk.source,f.n)
1479      ## also apply source parsing functions that I separated out into
1480      ## separate functions
1481      docs <- combine(docs,lonely$prefixed.lines(chunk.source))
1482      docs$title <- lonely$title.from.firstline(chunk.source)
1483      ##details<<
1484      ## If there is no explicit title on the first line of setClass, then
1485      ## one is made up from the class name.
1486      if ( 0 == length(docs$title) ){
1487        docs$title <- list(title=paste(class.name,"S4 class"))
1488      }
1489    ##details<<    ##details<<
1490    ## The class definition skeleton includes an \code{Objects from the Class}    ## The class definition skeleton includes an \code{Objects from the Class}
1491    ## section, to which any \code{##details<<} documentation chunks are    ## section, to which any \code{##details<<} documentation chunks are
# Line 637  Line 1509 
1509    }    }
1510    invisible(docs)    invisible(docs)
1511  }  }
1512    extract.docs.setMethod<- function # S4 mehtod inline documentation
1513    ### Using the same conventions as for functions, definitions of S4 methods
1514    ### in the form \code{setMethod(\dots)} are also located and
1515    ### scanned for inline comments.
1516    
1517    (doc.link,
1518    ### DocLink object as created by \code{extract.file.parse}.
1519     env,
1520     ### environment to find method source
1521    inlinedocs.exampleDir,
1522    ### A string pointing to the location where inlinedocs should search for external examples
1523    inlinedocs.exampleTrunk
1524    ### A regular expression used to identify the files containing external examples in the example directory
1525     ){
1526      funcSource=getMethodSrc(doc.link,env)
1527      method.name=getMethodName(doc.link,env)
1528      ##pp("funcSource",environment())
1529      docs=list()
1530      docs<- combine(docs,prefixed.lines(funcSource))
1531      ##pp("docs",environment())
1532      docs <- combine(docs,extract.xxx.chunks(funcSource,method.name))
1533      ##pp("docs",environment())
1534      docs <- combine(docs,title.from.firstline(funcSource,method.name))
1535      ##pp("docs",environment())
1536      docs <- combine(docs,mm.examples.from.testfile(method.name,inlinedocs.exampleDir,inlinedocs.exampleTrunk))
1537      docs
1538    }
1539    createObjects <- function(code){
1540      ### the function creates the environment object lists and expression by parsing all the code files
1541      ### Is is factored out to make writing tests easier
1542      ### since we often need the objects and the environment
1543      ### they inhabit
1544      e <- new.env()
1545      ## KMP 2011-03-09 fix problem with DocLink when inlinedocs ran on itself
1546      ## Error in assignClassDef(Class, classDef, where) :
1547      ##   Class "DocLink" has a locked definition in package "inlinedocs"
1548      ## Traced to "where" argument in setClassDef which defaults to topenv()
1549      ## which in turn is inlinedocs when processing inlinedocs package, hence
1550      ## the clash. The following works (under R 2.12.2), so that the topenv()
1551      ## now finds e before finding the inlinedocs environment.
1552    
1553      #old <- options(keep.source=TRUE,topLevelEnvironment=e)
1554      old <- options(topLevelEnvironment=e)
1555      on.exit(options(old))
1556      exprs <- parse(text=code,keep.source=TRUE)
1557      ## TDH 2011-04-07 set this so that no warnings about creating a fake
1558      ## package when we try to process S4 classes defined in code
1559      e$.packageName <- "inlinedocs.processor"
1560      for (i in exprs){
1561          eval(i, e)
1562      }
1563      objs <- sapply(ls(e),get,e,simplify=FALSE) # note that ls will not find S4 classes nor methods for generic functions
1564      list(objs=objs,env=e,exprs=exprs)
1565    }
1566    
1567  extract.docs.code <- function  
1568  ### Write code to a file and parse it to r objs, then run all the  apply.parsers<- function
1569  ### parsers and return the documentation list.  ### Parse code to r objs, then run all the parsers and return the
1570    ### documentation list.
1571  (code,  (code,
1572  ### Character vector of code lines.  ### Character vector of code lines.
1573   parsers,   parsers=default.parsers,
1574  ### List of Parser Functions.  ### List of Parser Functions.
1575   verbose=TRUE,   verbose=FALSE,
1576  ### Echo names of Parser Functions?  ### Echo names of Parser Functions?
1577    inlinedocs.exampleDir,
1578    ### A string pointing to the location where inlinedocs should search for external examples
1579    inlinedocs.exampleTrunk,
1580    ### A string used to identify the files containing external examples in the example directory. All file names of external examples have to start with this string
1581   ...   ...
1582  ### Additional arguments to pass to Parser Functions.  ### Additional arguments to pass to Parser Functions.
1583   ){   ){
1584    code.file <- tempfile()    l=createObjects(code)# note that ls will not find S4 classes nor methods for generic functions
1585    writeLines(code,code.file)    objs=l[["objs"]]
1586    e <- new.env()    e=l[["env"]]
1587    old <- options(keep.source.pkgs=TRUE)    exprs=l[["exprs"]]
1588    tryCatch(suppressWarnings(sys.source(code.file,e)),error=function(e){    docs <- list()
     stop("source ",code.file," failed with error:\n",e)  
   })  
   options(old)  
   objs <- sapply(ls(e),get,e,simplify=FALSE)  
1589    
1590    ## apply parsers in sequence to code and objs    ## apply parsers in sequence to code and objs
1591    docs <- list()    if(verbose)cat("Applying parsers:\n")
1592    for(i in seq_along(parsers)){    for(i in seq_along(parsers)){
1593      N <- names(parsers[i])      N <- names(parsers[i])
1594      if(verbose){      if(verbose){
1595        if(is.character(N) && N!=""){        if(is.character(N) && N!=""){
1596          cat(N," ",sep="")          cat(" this is parser:",N,"\n",sep="")
1597        }else cat('. ')        }else cat('.\n')
1598      }      }
1599      p <- parsers[[i]]      p <- parsers[[i]]
1600      ## This is the argument list that each parser receives:      ## This is the argument list that each parser receives:
1601      L <- p(code=code,objs=objs,docs=docs,...)      L <- p(
1602            code=code,
1603            objs=objs,
1604            docs=docs,
1605            env=e,
1606            inlinedocs.exampleDir=inlinedocs.exampleDir,
1607            inlinedocs.exampleTrunk=inlinedocs.exampleTrunk,
1608            ...
1609            )
1610      docs <- combine(docs,L)      docs <- combine(docs,L)
1611    }    }
1612      ## post-process to collapse all character vectors
1613      for(i in seq_along(docs)){
1614        for(j in seq_along(docs[[i]])){
1615          if(names(docs[[i]])[j]!=".s3method")
1616          docs[[i]][[j]] <- paste(docs[[i]][[j]],collapse="\n")
1617        }
1618     }
1619    if(verbose)cat("\n")    if(verbose)cat("\n")
1620    docs  
1621      return(list(docs=docs,env=e,objs=objs,exprs=exprs))
1622  ### A list of extracted documentation from code.  ### A list of extracted documentation from code.
1623  }  }
1624    
1625    ### Names of Parser Functions that operate on the desc arg.
1626    descfile.names <- c("author.from.description","edit.package.file")
1627    
1628    ### Names of Parser Functions that do NOT use the desc arg.
1629    non.descfile.names <-
1630      names(default.parsers)[!names(default.parsers)%in%descfile.names]
1631    
1632    ### Parsers that operate only on R code, independently of the
1633    ### description file.
1634    nondesc.parsers <- default.parsers[non.descfile.names]
1635    
1636    extract.docs.file <- structure(function
1637    ### Apply all parsers relevant to extract info from just 1 code file.
1638    (f,
1639    ### File name of R code to read and parse.
1640     parsers=NULL,
1641    ### Parser Functions to use to parse the code and extract
1642    ### documentation.
1643    inlinedocs.exampleDir=file.path("..","..","inst","tests"),
1644    ### A string pointing to the location where inlinedocs should search for external examples
1645    inlinedocs.exampleTrunk="example.",
1646    ### A string used to identify the files containing external examples in the example directory. All file names of external examples have to start with this string
1647     ...
1648    ### Other arguments to pass to Parser Functions.
1649     ){
1650      if(is.null(parsers))parsers <- nondesc.parsers
1651      apply.parsers(
1652            readLines(f),
1653            parsers,
1654            verbose=FALSE,
1655            inlinedocs.exampleDir,
1656            inlinedocs.exampleTrunk,
1657            ...
1658            )[["docs"]]
1659    },ex=function(){
1660      f <- system.file("silly","R","silly.R",package="inlinedocs")
1661      extract.docs.file(f)
1662    })
1663    

Legend:
Removed from v.105  
changed lines
  Added in v.396

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