github.com/elliott5/community@v0.14.1-0.20160709191136-823126fb026a/app/public/codemirror/mode/r/index.html (about)

     1  <!doctype html>
     2  
     3  <title>CodeMirror: R mode</title>
     4  <meta charset="utf-8"/>
     5  <link rel=stylesheet href="../../doc/docs.css">
     6  
     7  <link rel="stylesheet" href="../../lib/codemirror.css">
     8  <script src="../../lib/codemirror.js"></script>
     9  <script src="r.js"></script>
    10  <style>
    11        .CodeMirror { border-top: 1px solid silver; border-bottom: 1px solid silver; }
    12        .cm-s-default span.cm-semi { color: blue; font-weight: bold; }
    13        .cm-s-default span.cm-dollar { color: orange; font-weight: bold; }
    14        .cm-s-default span.cm-arrow { color: brown; }
    15        .cm-s-default span.cm-arg-is { color: brown; }
    16      </style>
    17  <div id=nav>
    18    <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
    19  
    20    <ul>
    21      <li><a href="../../index.html">Home</a>
    22      <li><a href="../../doc/manual.html">Manual</a>
    23      <li><a href="https://github.com/codemirror/codemirror">Code</a>
    24    </ul>
    25    <ul>
    26      <li><a href="../index.html">Language modes</a>
    27      <li><a class=active href="#">R</a>
    28    </ul>
    29  </div>
    30  
    31  <article>
    32  <h2>R mode</h2>
    33  <form><textarea id="code" name="code">
    34  # Code from http://www.mayin.org/ajayshah/KB/R/
    35  
    36  # FIRST LEARN ABOUT LISTS --
    37  X = list(height=5.4, weight=54)
    38  print("Use default printing --")
    39  print(X)
    40  print("Accessing individual elements --")
    41  cat("Your height is ", X$height, " and your weight is ", X$weight, "\n")
    42  
    43  # FUNCTIONS --
    44  square <- function(x) {
    45    return(x*x)
    46  }
    47  cat("The square of 3 is ", square(3), "\n")
    48  
    49                   # default value of the arg is set to 5.
    50  cube <- function(x=5) {
    51    return(x*x*x);
    52  }
    53  cat("Calling cube with 2 : ", cube(2), "\n")    # will give 2^3
    54  cat("Calling cube        : ", cube(), "\n")     # will default to 5^3.
    55  
    56  # LEARN ABOUT FUNCTIONS THAT RETURN MULTIPLE OBJECTS --
    57  powers <- function(x) {
    58    parcel = list(x2=x*x, x3=x*x*x, x4=x*x*x*x);
    59    return(parcel);
    60  }
    61  
    62  X = powers(3);
    63  print("Showing powers of 3 --"); print(X);
    64  
    65  # WRITING THIS COMPACTLY (4 lines instead of 7)
    66  
    67  powerful <- function(x) {
    68    return(list(x2=x*x, x3=x*x*x, x4=x*x*x*x));
    69  }
    70  print("Showing powers of 3 --"); print(powerful(3));
    71  
    72  # In R, the last expression in a function is, by default, what is
    73  # returned. So you could equally just say:
    74  powerful <- function(x) {list(x2=x*x, x3=x*x*x, x4=x*x*x*x)}
    75  </textarea></form>
    76      <script>
    77        var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
    78      </script>
    79  
    80      <p><strong>MIME types defined:</strong> <code>text/x-rsrc</code>.</p>
    81  
    82      <p>Development of the CodeMirror R mode was kindly sponsored
    83      by <a href="https://twitter.com/ubalo">Ubalo</a>.</p>
    84  
    85    </article>