R/parseSourceFile.R

parseSourceFile <-
    function # ^ Parse a R-source-code regarding annotated documentation
### ^ Annotation has to look like
### ^    myFun <-
### ^        function  # ^ Compute something
### ^    ### ^ Optional multiline
### ^    ### ^ description
### ^    (
### ^       x      # ^ argument x is something;
### ^              # ^ could also be multiline
### ^      ,y      # ^ argument y is another something
### ^    )
### ^    {
### ^        doSomething(x,y)
### ^    }    # ^ Returns this
(
    f                         # ^ source-code-file
   ,p   = '\\s*# \\^\\s*'   # ^ general annotation pattern (default '# ^')
)
{
    lns. <- readLines(f)
    lns  <-
        strsplit(sub("\\s*(<-|=)\\s*\n*\\s*function", "  = function",
            paste(lns., collapse = "\n" )), "\n")[[1]]
    cmts <- lns[grep(p, lns)]
    parseFunction(cmts)
    ## TODO: iterate over functions
}                                  # ^ Returns a 'FunctionDoc'
michelk/annotSrcDoc.R documentation built on May 22, 2019, 9:55 p.m.