Guest User

Untitled

a guest
Feb 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'pp'
  3. Dir.chdir("/Library/Frameworks/R.framework/Versions/Current/Resources/library")
  4. resources = Dir.glob("*/latex/*.tex")
  5. # puts resources
  6. results = ""
  7. resources.each do |file|
  8. tex = File.read(file)
  9. terms = tex.scan(/\\begin\{verbatim\}\n(.*)\\end\{verbatim\}/m)
  10. #.split(/\n+(?=[\w.]+\()/)
  11. results << terms[0][0] unless terms.empty?
  12. #.map{|line| line.gsub(/\n|( )/,"")}
  13. end
  14. results.gsub!(/\s*#+(\s.*|)$/,"") # Removes comments. Need to watch out for something like "#"
  15. results.gsub!(/^\s*[\w.:]+\s*\n/,"") # Removes stupid lines like a:b
  16. results.gsub!(/^(\.|<)\w.*|.*(\?topic|@name|survexp\.uswhite).*/,"") # removes function names starting with a dot, as well as other random stuff
  17. results.gsub!(/.*value\n/,"") # Removes lines like: tsp(x) <- value
  18. results.gsub!(/^\w\s+.*\n/,"") # Removes lines like: R CMD ...
  19. results.gsub!(/^\w?(?:\[|\$).*\n/,"") # Removes lines starting with: x[[...]] or x$name
  20. results.gsub!(/^[\w.:+-\/><\s;!&|"]*\n/,"") # Removes things like: time1 + time2
  21. results.gsub!(/^(?:if|for|while|function)\(.*\n/,"") # Removes definitions of if/for/while/function
  22. results.gsub!(/\n(?![\w.]+\()/," ") # Brings together arguments on different lines
  23. results.gsub!(/[\t ]+/," ")
  24. results.gsub!(/\s+$/,"")
  25. puts results.split("\n").sort.uniq.join("\n")
Add Comment
Please, Sign In to add comment