Mercurial
comparison .cms/lib/codemirror/mode/r/index.html @ 0:78edf6b517a0 draft
24.10
author | Coffee CMS <info@coffee-cms.ru> |
---|---|
date | Fri, 11 Oct 2024 22:40:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78edf6b517a0 |
---|---|
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/5"><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/codemirror5">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 X <- list(height = 5.4, weight = 54) | |
35 cat("Printing objects: "); print(X) | |
36 print("Accessing individual elements:") | |
37 cat(sprintf("Your height is %s and your weight is %s\n", X$height, X$weight)) | |
38 | |
39 # Functions: | |
40 square <- function(x) { | |
41 return(x * x) | |
42 } | |
43 cat(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: | |
47 square <- function(x) { | |
48 x * x | |
49 } | |
50 # or, for functions with short content: | |
51 square <- function(x) x * x | |
52 | |
53 # Function arguments with default values: | |
54 cube <- function(x = 5) x * x * x | |
55 cat(sprintf("Calling cube with 2 : %s\n", cube(2)) # will give 2^3 | |
56 cat(sprintf("Calling cube : %s\n", cube()) # will default to 5^3. | |
57 | |
58 powers <- function(x) list(x2 = x*x, x3 = x*x*x, x4 = x*x*x*x) | |
59 | |
60 cat("Powers of 3: "); print(powers(3)) | |
61 | |
62 # Data frames | |
63 df <- data.frame(letters = letters[1:5], '#letter' = 1:5) | |
64 print(df$letters) | |
65 print(df$`#letter`) | |
66 | |
67 # Operators: | |
68 m1 <- matrix(1:6, 2, 3) | |
69 m2 <- m1 %*% t(m1) | |
70 cat("Matrix product: "); print(m2) | |
71 | |
72 # Assignments: | |
73 a <- 1 | |
74 b <<- 2 | |
75 c = 3 | |
76 4 -> d | |
77 5 ->> 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> |