all repos — NoPaste @ 29b774f090102303e43cf939b38ac2083e62d9f1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/r/index.html (view raw)

 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="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></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">
34X <- list(height = 5.4, weight = 54)
35cat("Printing objects: "); print(X)
36print("Accessing individual elements:")
37cat(sprintf("Your height is %s and your weight is %s\n", X$height, X$weight))
38
39# Functions:
40square <- function(x) {
41  return(x * x)
42}
43cat(sprintf("The square of 3 is %s\n", square(3)))
44
45# In R, the last expression in a function is, by default, what is
46# returned. The idiomatic way to write the function is:
47square <- function(x) {
48  x * x
49}
50# or, for functions with short content:
51square <- function(x) x * x
52
53# Function arguments with default values:
54cube <- function(x = 5) x * x * x
55cat(sprintf("Calling cube with 2 : %s\n", cube(2))  # will give 2^3
56cat(sprintf("Calling cube        : %s\n", cube())   # will default to 5^3.
57
58powers <- function(x) list(x2 = x*x, x3 = x*x*x, x4 = x*x*x*x)
59
60cat("Powers of 3: "); print(powers(3))
61
62# Data frames
63df <- data.frame(letters = letters[1:5], '#letter' = 1:5)
64print(df$letters)
65print(df$`#letter`)
66
67# Operators:
68m1 <- matrix(1:6, 2, 3)
69m2 <- m1 %*% t(m1)
70cat("Matrix product: "); print(m2)
71
72# Assignments:
73a <- 1
74b <<- 2
75c = 3
764 -> d
775 ->> e
78</textarea></form>
79    <script>
80      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
81    </script>
82
83    <p><strong>MIME types defined:</strong> <code>text/x-rsrc</code>.</p>
84
85    <p>Development of the CodeMirror R mode was kindly sponsored
86    by <a href="https://twitter.com/ubalo">Ubalo</a>.</p>
87
88  </article>