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