R Programming Language

Source Code Highlighting Project

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

My goal for this project is to improve online collaboration. Sharing code on the Internet is suppose to be easy and informative. Use this package to highlight R programs.

Grab code you want by simply highlighting with your mouse. Note: to grab code without line numbers, just click on the first line of source code you want just to the right of the line numbers and drag from there,otherwise you will end up grabbing the line numbers too. Click on links automatically generated within the source code to help new users learn more quickly.

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 second draft of the R (with RHIPE) language highlighter file for GeSHi. Sample usage can be found on LectureMaker’s Math TV Internet platform.

Contact me if you would like to help with this project: automatic generation of all R language constructs and packages, and tutorials from my video studio optimized for source code documentation:
Ron Fredericks, software ecosystem innovator
ronf@LectureMaker.com
(408-390-1895

code=php
  1. < ?php
  2. /*************************************************************************************
  3. * r.php
  4. * ———–
  5. * Author: Ron Fredericks (ronf@LectureMaker.com)
  6. * Copyright: (c) 2009-11 Ron Fredericks (http://www.LectureMaker.com)
  7. * Release Version: 0.0.0.2
  8. * Date Started: 2009/03/28
  9. * Last Updated 2011/02/14
  10. *
  11. * R language file for GeSHi.
  12. *
  13. * CHANGES
  14. * ——-
  15. * 2009/03/29 (0.0.1)
  16. *   -  First Internal Release
  17.   * 2011/02/14 (0.0.2)
  18. *   -  Second Internal Release with RHIPE support
  19. *
  20. *
  21. * References
  22. * ———-
  23. * Another R GeSHi with no meat? http://organicdesign.co.nz/GeSHi/R.php
  24. * SourceForge R discussion: http://sourceforge.net/tracker/?func=detail&aid=2276025&group_id=114997&atid=670234
  25. *
  26. *************************************************************************************
  27. *
  28. *     This file is part of GeSHi.
  29. *
  30. *   GeSHi is free software; you can redistribute it and/or modify
  31. *   it under the terms of the GNU General Public License as published by
  32. *   the Free Software Foundation; either version 2 of the License, or
  33. *   (at your option) any later version.
  34. *
  35. *   GeSHi is distributed in the hope that it will be useful,
  36. *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38. *   GNU General Public License for more details.
  39. *
  40. *   You should have received a copy of the GNU General Public License
  41. *   along with GeSHi; if not, write to the Free Software
  42. *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  43. *
  44. ************************************************************************************/
  45.  
  46. $language_data = array (
  47.         ‘LANG_NAME’ => ‘r’,
  48.         ‘COMMENT_SINGLE’ => array(1 => ‘#’),
  49.         ‘COMMENT_MULTI’ => array(),
  50.         ‘CASE_KEYWORDS’ => GESHI_CAPS_NO_CHANGE,
  51.         ‘QUOTEMARKS’ => array(),
  52.         ‘ESCAPE_CHAR’ => ,
  53.         ‘KEYWORDS’ => array(
  54.                         1 => array(
  55.                                         ‘global’, ‘otherwise’, ‘persistent’, ‘return’,
  56.                                         ‘switch’, ‘try’
  57.                         ),
  58.                 2 => array(               // Graphics package
  59.                                    ‘plot’,
  60.                                    ‘abline’,
  61.                                    ‘lines’
  62.                                    ‘hist’,
  63.                                    ‘residuals’                         
  64.                         ),
  65.                         3 => array(  // The Normal Distribution
  66.                                    ‘rnorm’                         
  67.                         ),
  68.                         4 => array(  // LM Distribution
  69.                                    ‘lm’,
  70.                                    ‘lowess’
  71.                         ),
  72.                         5 => array(  // Summary for LM Distribution
  73.                                    ‘summary’
  74.                         ),
  75.                         6 => array(  // Log
  76.                                         ‘exp’
  77.                         ),
  78.                         7 => array(  // Evaluate an (Unevaluated) Expression
  79.                                         ‘expression’
  80.                         ),
  81.                         8 => array(  // base package 2.5 links
  82.                                         ‘any’,
  83.                                         ‘append’,
  84.                                         ‘c’,
  85.                                         ‘do.call’,
  86.                                         ‘function’,
  87.                                         ‘lapply’,
  88.                                         ‘length’,
  89.                                         ‘library’,
  90.                                         ‘list’,
  91.                                         ‘load’,
  92.                                         ‘nrow’,
  93.                                         ‘paste’,
  94.                                         ‘seq’,
  95.                                         ‘strsplit’,
  96.                                         ‘sum’,
  97.                                         ‘unlist’
  98.                         ),
  99.                         9 => array(  // base package 2.5 seq references, not in base package version 2.1
  100.                                         ‘seq_along’,
  101.                         ),
  102.                         ‘r_control’ => array(
  103.                                         ‘if’, ‘else’, ‘for’, ‘while’, ‘repeat’, ‘break’,
  104.                                         ‘next’
  105.                         ),
  106.                         ‘r_null’ => array(
  107.                                         ‘as.null’, ‘is.null’, ‘NULL’
  108.                         ),
  109.                         ‘r_round’ => array(
  110.                                         ‘ceiling’, ‘floor’, ‘trunc’, ’round’, ‘signif’,
  111.                                         ‘zapsmall’
  112.                         ),                       
  113.                         ‘rhipe_rhcollect’ => array( 
  114.                                         ‘rhcollect’
  115.                         ),
  116.                         ‘rhipe_rhex’ => array( 
  117.                                         ‘rhex’
  118.                         ),
  119.                         ‘rhipe_rhgetkey’ => array( 
  120.                                         ‘rhgetkey’
  121.                         ),     
  122.                         ‘rhipe_rhlapply’  => array( 
  123.                                         ‘rhlapply’
  124.                         ),     
  125.                         ‘rhipe_rhmr’ => array( 
  126.                                         ‘rhmr’
  127.                         ),     
  128.                         ‘rhipe_rhput’ => array( 
  129.                                         ‘rhput’
  130.                         )                     
  131.                                        
  132.                 ),
  133.         ‘SYMBOLS’ => array(
  134.                 ‘…’ , ‘(‘, ‘)’, ‘< -’, ‘~’
  135.                 ),
  136.         ‘CASE_SENSITIVE’ => array(
  137.                 GESHI_COMMENTS => true,
  138.                 1 => false,
  139.                 2 => false
  140.                 //3 => false,
  141.                 //4 => false,
  142.                 ),
  143.         ‘STYLES’ => array(
  144.                 ‘KEYWORDS’ => array(
  145.                         1 => ‘color: #0000FF;’// blue
  146.                         2 => ‘color: #0000FF;’,
  147.                         3 => ‘color: #0000FF;’,
  148.             4 => ‘color: #0000FF;’,
  149.                         5 => ‘color: #0000FF;’,
  150.                         6 => ‘color: #0000FF;’,
  151.                         7 => ‘color: #0000FF;’,
  152.                         8 => ‘color: #0000FF;’,
  153.                         9 => ‘color: #0000FF;’,
  154.                         ‘r_control’ => ‘color: #0000FF;’,
  155.                         ‘r_null’ => ‘color: #003300;’// dark green
  156.                         ‘r_round’ => ‘color: #003300;’// dark green
  157.                         ‘rhipe_rhcollect’ => ‘color: #993300;’, // brown
  158.                         ‘rhipe_rhgetkey’ => ‘color: #993300;’,
  159.                         ‘rhipe_rhex’ => ‘color: #993300;’,
  160.                         ‘rhipe_rhlapply’ => ‘color: #993300;’,
  161.                         ‘rhipe_rhmr’ => ‘color: #993300;’,
  162.                         ‘rhipe_rhput’ => ‘color: #993300;’
  163.                         ),
  164.                 ‘COMMENTS’ => array(
  165.                         1 => ‘color: #228B22;’,
  166.                         ),
  167.                 ‘ESCAPE_CHAR’ => array(
  168.             0 =>
  169.                         ),
  170.                 ‘BRACKETS’ => array(
  171.             0 => ‘color: #080;’
  172.                         ),
  173.                 ‘STRINGS’ => array(
  174.                         //0 => ‘color: #A020F0;’
  175.                         ),
  176.                 ‘NUMBERS’ => array(
  177.             0 => ‘color: #ff0000;’
  178.                         ),
  179.                 ‘METHODS’ => array(
  180.             1 => ,
  181.             2 =>
  182.                         ),
  183.                 ‘SYMBOLS’ => array(
  184.             0 => ‘color: #080;’
  185.                         ),
  186.                 ‘REGEXPS’ => array(
  187.             0 => ‘color:#A020F0;’
  188.                         ),
  189.                 ‘SCRIPT’ => array(
  190.             0 =>
  191.                         )
  192.                 ),
  193.         ‘URLS’ => array(
  194.                 1 => ‘http://astrostatistics.psu.edu/datasets/R/html/base/html/00Index.html’,
  195.                 2 => ‘http://astrostatistics.psu.edu/su07/R/html/graphics/html/{FNAME}.html’,
  196.                 3 => ‘http://astrostatistics.psu.edu/su07/R/html/stats/html/Normal.html’,
  197.                 4 => ‘http://astrostatistics.psu.edu/su07/R/html/stats/html/{FNAME}.html’,
  198.                 5 => ‘http://astrostatistics.psu.edu/su07/R/html/stats/html/summary.lm.html’,
  199.                 6 => ‘http://astrostatistics.psu.edu/su07/R/html/base/html/Log.html’,
  200.                 7 => ‘http://astrostatistics.psu.edu/datasets/R/html/base/html/eval.html’,
  201.                 8 => ‘http://www.iiap.res.in/astrostat/School07/R/html/base/html/{FNAME}.html’// base package version 2.5
  202.                 9 => ‘http://www.iiap.res.in/astrostat/School07/R/html/base/html/seq.html’,               // base package version 2.5
  203.                 ‘r_control’ => ‘http://www.astrostatistics.psu.edu/datasets/R/html/base/html/Control.html’,
  204.                 ‘r_null’ => ‘http://www.astrostatistics.psu.edu/datasets/R/html/base/html/NULL.html’,
  205.                 ‘r_round’ => ‘http://www.iiap.res.in/astrostat/School07/R/html/base/html/Round.html’,
  206.                 ‘rhipe_rhcollect’ => ‘http://www.stat.purdue.edu/~sguha/rhipe/doc/html/mr.html#rhcollect-writing-data-to-hadoop-mapreduce’,
  207.                 ‘rhipe_rhex’ => ‘http://www.stat.purdue.edu/~sguha/rhipe/doc/html/functions.html#rhex-submitting-a-mapreduce-r-object-to-hadoop’,
  208.                 ‘rhipe_rhgetkey’ => ‘http://www.stat.purdue.edu/~sguha/rhipe/doc/html/functions.html#rhgetkeys-reading-values-from-map-files’,
  209.                 ‘rhipe_rhlapply’ => ‘http://www.stat.purdue.edu/~sguha/rhipe/doc/html/rhlapply.html’,
  210.                 ‘rhipe_rhmr’ => ‘http://www.stat.purdue.edu/~sguha/rhipe/doc/html/mr.html#rhmr-creating-the-mapreduce-object’,
  211.                 ‘rhipe_rhput’ => ‘http://www.stat.purdue.edu/~sguha/rhipe/doc/html/functions.html#rhput-copying-to-the-hdf’
  212.                 ),
  213.         ‘OOLANG’ => true,
  214.         ‘OBJECT_SPLITTERS’ => array(
  215.                 1 => ‘.’,
  216.                 2 => ‘::’
  217.                 ),
  218.         ‘REGEXPS’ => array(
  219.         0 => array(
  220.             GESHI_SEARCH => "([^\w])’([^\\n\\r']*)’",
  221.             GESHI_REPLACE => \\2′,
  222.             GESHI_MODIFIERS => ,
  223.             GESHI_BEFORE => "\\1′",
  224.             GESHI_AFTER => "’"
  225.                 )
  226.                 ),
  227.         ‘STRICT_MODE_APPLIES’ => GESHI_NEVER,
  228.         ‘SCRIPT_DELIMITERS’ => array(
  229.                 ),
  230.         ‘HIGHLIGHT_STRICT_BLOCK’ => array(
  231.                 )
  232. );
  233.  
  234. ?>

8 Responses to “R Programming Language”

  1. RHIPE: An Interface Between Hadoop and R for Large and Complex Data Analysis | LectureMaker, LLC Says:

    [...] 132 languages plus my own R highlighter. [...]

  2. RHIPE: An Interface Between Hadoop and R for Large and Complex Data Analysis | R User Groups Says:

    [...] technique. One special feature I add to my R video recordings is the addition of my own R source code highlighting and math symbol publishing plugins for WordPress blogs. The highlighting is unique in that R [...]

  3. Linx Says:

    XmVCZF I’m not easily impressed. . . but that’s impressing me! :)

  4. php directory Says:

    Thanks for another informative site. Where else could I get that kind of information written in such an ideal way? I’ve a project that I am just now working on, and I’ve been on the look out for such information.

  5. the heart of being helpful Says:

    Yes! Finally someone writes about early childhood music therapy and autism spectrum disorders.

  6. linkedin endorsement generator Says:

    As a result, mobile and email marketing have become important sales and
    marketing tools; and although traditionally viewed as the
    “desktop” communication, email is becoming increasingly mobile as well because
    of the increasing popularity of smart phones. The first one
    lets you access any profile on Linked – In, which can help you find exactly what you are looking for faster.
    In your Profile’s Experience section, you can add positions that show how you came to be qualified for an executive role,
    even if you omit the details associated with these jobs.

  7. ????? ?????? Says:

    Marvelous, what a weblog it is! This web site gives useful data to us,
    keep it up.

    Check out my blog post: ????? ??????

  8. Latasha Says:

    Hey there! Do you use Twitter? I’d like to follow you if
    that would be ok. I’m absolutely enjoying your blog and look forward to new updates.

Leave a Reply

What is 3 + 7 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)