Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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