diff options
author | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
---|---|---|
committer | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
commit | 03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch) | |
tree | c51112223ceb9121cd595a60335eb2795215590f /imports/codemirror/mode/r/index.html | |
parent | fcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff) | |
parent | 053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff) | |
download | ninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz |
Merge branch 'pentool' into brushtool
Conflicts:
imports/codemirror/mode/scheme/scheme.js
js/tools/BrushTool.js
Diffstat (limited to 'imports/codemirror/mode/r/index.html')
-rwxr-xr-x | imports/codemirror/mode/r/index.html | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/imports/codemirror/mode/r/index.html b/imports/codemirror/mode/r/index.html new file mode 100755 index 00000000..69775055 --- /dev/null +++ b/imports/codemirror/mode/r/index.html | |||
@@ -0,0 +1,73 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: R mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="r.js"></script> | ||
8 | <style> | ||
9 | .CodeMirror { border-top: 1px solid silver; border-bottom: 1px solid silver; } | ||
10 | .cm-s-default span.cm-semi { color: blue; font-weight: bold; } | ||
11 | .cm-s-default span.cm-dollar { color: orange; font-weight: bold; } | ||
12 | .cm-s-default span.cm-arrow { color: brown; } | ||
13 | .cm-s-default span.cm-arg-is { color: brown; } | ||
14 | </style> | ||
15 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
16 | </head> | ||
17 | <body> | ||
18 | <h1>CodeMirror: R mode</h1> | ||
19 | <form><textarea id="code" name="code"> | ||
20 | # Code from http://www.mayin.org/ajayshah/KB/R/ | ||
21 | |||
22 | # FIRST LEARN ABOUT LISTS -- | ||
23 | X = list(height=5.4, weight=54) | ||
24 | print("Use default printing --") | ||
25 | print(X) | ||
26 | print("Accessing individual elements --") | ||
27 | cat("Your height is ", X$height, " and your weight is ", X$weight, "\n") | ||
28 | |||
29 | # FUNCTIONS -- | ||
30 | square <- function(x) { | ||
31 | return(x*x) | ||
32 | } | ||
33 | cat("The square of 3 is ", square(3), "\n") | ||
34 | |||
35 | # default value of the arg is set to 5. | ||
36 | cube <- function(x=5) { | ||
37 | return(x*x*x); | ||
38 | } | ||
39 | cat("Calling cube with 2 : ", cube(2), "\n") # will give 2^3 | ||
40 | cat("Calling cube : ", cube(), "\n") # will default to 5^3. | ||
41 | |||
42 | # LEARN ABOUT FUNCTIONS THAT RETURN MULTIPLE OBJECTS -- | ||
43 | powers <- function(x) { | ||
44 | parcel = list(x2=x*x, x3=x*x*x, x4=x*x*x*x); | ||
45 | return(parcel); | ||
46 | } | ||
47 | |||
48 | X = powers(3); | ||
49 | print("Showing powers of 3 --"); print(X); | ||
50 | |||
51 | # WRITING THIS COMPACTLY (4 lines instead of 7) | ||
52 | |||
53 | powerful <- function(x) { | ||
54 | return(list(x2=x*x, x3=x*x*x, x4=x*x*x*x)); | ||
55 | } | ||
56 | print("Showing powers of 3 --"); print(powerful(3)); | ||
57 | |||
58 | # In R, the last expression in a function is, by default, what is | ||
59 | # returned. So you could equally just say: | ||
60 | powerful <- function(x) {list(x2=x*x, x3=x*x*x, x4=x*x*x*x)} | ||
61 | </textarea></form> | ||
62 | <script> | ||
63 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | ||
64 | </script> | ||
65 | |||
66 | <p><strong>MIME types defined:</strong> <code>text/x-rsrc</code>.</p> | ||
67 | |||
68 | <p>Development of the CodeMirror R mode was kindly sponsored | ||
69 | by <a href="http://ubalo.com/">Ubalo</a>, who hold | ||
70 | the <a href="LICENSE">license</a>.</p> | ||
71 | |||
72 | </body> | ||
73 | </html> | ||