File: tangle1.R

package info (click to toggle)
r-cran-xml 3.99-0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: ansic: 6,659; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (17 lines) | stat: -rw-r--r-- 571 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
tangleR = xxx_getRCode =  # conflicts with getRCode in xmlInternalSource.R
function(doc, tags =  c("code", "plot", "function"), out = gsub("\\.[a-zA-Z]+$", ".R", docName(doc)))
{
   if(is.character(doc))
      doc = xmlParse(doc)

   xp = sprintf("//r:%s[not(@eval='false') and not(ancestor::section[@eval='false'])]",
                    tags)
   code = xpathSApply(doc, paste(xp, collapse = " | "), xmlValue, namespaces = c("r" = "http://www.r-project.org"))

   if(length(out) && !is.na(out)) {
      cat(code, sep = "\n", file = out)
      out
   } else
     code
}