R Programming Language

This is my initial R Programming Language plug-in for GeSHi. Not much to it for now. But it does demonstrate the use of packages, and hot links on documentation for each language method.

Sample code

Code (r)
  1. x <- rnorm(100)            # 100 random numbers from a normal(0,1) distribution
  2. y <- exp(x) + rnorm(100)   # an exponential function with error
  3. result <- lm(y ~ x)        # regress x on y and store the results
  4. summary(result)            # print the regression results
  5. plot(x,y)                  # pretty obvious what this does
  6. abline(result)             # add the regression line to the plot
  7. lines(lowess(x,y), col=2)  # add a nonparametric regression line (a smoother)
  8. hist(result$residuals)     # histogram of the residuals from the regression
  9. # source code reference: http://bayes.math.montana.edu/Rweb/Rweb.general.html

You can click on the highlighted methods, or copy the code above and paste it into a web version of R called RWeb

GeSHi file

Here I present my first draft of the R file for GeSHi

Code (php)
  1. <?php
  2. /*************************************************************************************
  3. * r.php
  4. * ———–
  5. * Author: Ron Fredericks (ronf@LectureMaker.com)
  6. * Copyright: (c) 2009 Ron Fredericks (http://www.LectureMaker.com)
  7. * Release Version: 0.0.0.1
  8. * Date Started: 2009/03/28
  9. *
  10. * R language file for GeSHi.
  11. *
  12. * CHANGES
  13. * ——-
  14. * 2009/03/29 (0.0.1)
  15. *   -  First Internal Release
  16. *
  17. * 2009/04/06
  18. *       -  Add references to Sekhon’s R Package docs
  19. *
  20. *
  21. * References
  22. * ———-
  23. * Some online R Package documentation:
  24. *            http://sekhon.berkeley.edu/library/index.html         2.4 docs
  25. *            http://astrostatistics.psu.edu/su07/R/html        2.5 docs
  26. *
  27. * Another R GeSHi with no meat? http://organicdesign.co.nz/GeSHi/R.php
  28. * SourceForge R discussion: http://sourceforge.net/tracker/?func=detail&aid=2276025&group_id=114997&atid=670234
  29. *
  30. *************************************************************************************
  31. *
  32. *     This file is part of GeSHi.
  33. *
  34. *   GeSHi is free software; you can redistribute it and/or modify
  35. *   it under the terms of the GNU General Public License as published by
  36. *   the Free Software Foundation; either version 2 of the License, or
  37. *   (at your option) any later version.
  38. *
  39. *   GeSHi is distributed in the hope that it will be useful,
  40. *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  42. *   GNU General Public License for more details.
  43. *
  44. *   You should have received a copy of the GNU General Public License
  45. *   along with GeSHi; if not, write to the Free Software
  46. *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  47. *
  48. ************************************************************************************/
  49.  
  50. $language_data = array (
  51.         ‘LANG_NAME’ => ‘r’,
  52.         ‘COMMENT_SINGLE’ => array(1 => ‘#’),
  53.         ‘COMMENT_MULTI’ => array(),
  54.         ‘CASE_KEYWORDS’ => GESHI_CAPS_NO_CHANGE,
  55.         ‘QUOTEMARKS’ => array(),
  56.         ‘ESCAPE_CHAR’ => ,
  57.         ‘KEYWORDS’ => array(
  58.                 1 => array(
  59.                         ‘function’, ‘global’, ‘if’, ‘otherwise’, ‘persistent’, ‘return’,
  60.                         ‘switch’, ‘try’, ‘while’,‘…’
  61.                         ),
  62.         2 => array(               // Graphics package
  63.                                    ‘plot’,
  64.                                    ‘abline’,
  65.                                    ‘lines’
  66.                                    ‘hist’,
  67.                                    ‘residuals’,                           
  68.                                 ),
  69.                         3 => array(  // The Normal Distribution
  70.                                    ‘rnorm’,                           
  71.                                 ),
  72.                                 4 => array(  // LM Distribution
  73.                                    ‘lm’,
  74.                                    ‘lowess’,
  75.                                 ),
  76.                                 5 => array(  // Summary for LM Distribution
  77.                                    ‘summary’,
  78.                                 ),
  79.                                 6 => array(  // Log
  80.                                         ‘exp’,
  81.                                         )
  82.                 ),
  83.         ‘SYMBOLS’ => array(
  84.                 ‘…’ , ‘(‘, ‘)’, ‘< -’, ‘~’
  85.                 ),
  86.         ‘CASE_SENSITIVE’ => array(
  87.                 GESHI_COMMENTS => true,
  88.                 1 => false,
  89.                 2 => false,
  90.                 //3 => false,
  91.                 //4 => false,
  92.                 ),
  93.         ‘STYLES’ => array(
  94.                 ‘KEYWORDS’ => array(
  95.                         1 => ‘color: #0000FF;’,
  96.                         2 => ‘color: #0000FF;’,
  97.                         3 => ‘color: #0000FF;’,
  98.             4 => ‘color: #0000FF;’,
  99.                         5 => ‘color: #0000FF;’,
  100.                         6 => ‘color: #0000FF;’
  101.                         ),
  102.                 ‘COMMENTS’ => array(
  103.                         1 => ‘color: #228B22;’,
  104.                         ),
  105.                 ‘ESCAPE_CHAR’ => array(
  106.             0 =>
  107.                         ),
  108.                 ‘BRACKETS’ => array(
  109.             0 => ‘color: #080;’
  110.                         ),
  111.                 ‘STRINGS’ => array(
  112.                         //0 => ‘color: #A020F0;’
  113.                         ),
  114.                 ‘NUMBERS’ => array(
  115.             0 => ‘color: #ff0000;’
  116.                         ),
  117.                 ‘METHODS’ => array(
  118.             1 => ,
  119.             2 =>
  120.                         ),
  121.                 ‘SYMBOLS’ => array(
  122.             0 => ‘color: #080;’
  123.                         ),
  124.                 ‘REGEXPS’ => array(
  125.             0 => ‘color:#A020F0;’
  126.                         ),
  127.                 ‘SCRIPT’ => array(
  128.             0 =>
  129.                         )
  130.                 ),
  131.         ‘URLS’ => array(
  132.                 1 => ,
  133.                 2 => ‘http://astrostatistics.psu.edu/su07/R/html/graphics/html/{FNAME}.html’,   // http://sekhon.berkeley.edu/library/graphics/html/{FNAME}.html
  134.                 3 => ‘http://astrostatistics.psu.edu/su07/R/html/stats/html/Normal.html’,              // http://sekhon.berkeley.edu/library/stats/html/Normal.html
  135.                 4 => ‘http://astrostatistics.psu.edu/su07/R/html/stats/html/{FNAME}.html’,           // http://sekhon.berkeley.edu/library/stats/html/{FNAME}.html
  136.                 5 => ‘http://astrostatistics.psu.edu/su07/R/html/stats/html/summary.lm.html’,   // http://sekhon.berkeley.edu/library/stats/html/summary.lm.html
  137.                 6 => ‘http://astrostatistics.psu.edu/su07/R/html/base/html/Log.html’            // http://sekhon.berkeley.edu/library/base/html/Log.html
  138.                 ),
  139.         ‘OOLANG’ => true,
  140.         ‘OBJECT_SPLITTERS’ => array(
  141.                 1 => ‘.’,
  142.                 2 => ‘::’
  143.                 ),
  144.         ‘REGEXPS’ => array(
  145.         0 => array(
  146.             GESHI_SEARCH => "([^\w])’([^\\n\\r']*)’",
  147.             GESHI_REPLACE => \\2′,
  148.             GESHI_MODIFIERS => ,
  149.             GESHI_BEFORE => "\\1′",
  150.             GESHI_AFTER => "’"
  151.                 )
  152.                 ),
  153.         ‘STRICT_MODE_APPLIES’ => GESHI_NEVER,
  154.         ‘SCRIPT_DELIMITERS’ => array(
  155.                 ),
  156.         ‘HIGHLIGHT_STRICT_BLOCK’ => array(
  157.                 )
  158. );
  159.  
  160. ?>

One Response to “R Programming Language”

  1. Ron Fredericks Says:

    Viewers can learn more about the R language from my online video posted to LectureMaker.com:
    http://www.lecturemaker.com/2009/02/r-kickoff-video/

Leave a Reply