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