scicom 0.3.0-java → 0.4.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +239 -55
- data/Rakefile +58 -5
- data/config.rb +34 -2
- data/doc/Array.html +153 -0
- data/doc/Java/OrgRenjinSexp/LogicalArrayVector.html +120 -0
- data/doc/Java/OrgRenjinSexp/StringArrayVector.html +133 -0
- data/doc/Java/RbScicom/MDDoubleVector.html +133 -0
- data/doc/MDArray.html +153 -0
- data/doc/MergeObservable.html +347 -0
- data/doc/NegRange.html +166 -0
- data/doc/PackageManager.html +823 -0
- data/doc/PackageManager/ParseXML.html +595 -0
- data/doc/Range.html +243 -0
- data/doc/Renjin.html +2210 -0
- data/doc/Renjin/Attributes.html +401 -0
- data/doc/Renjin/Closure.html +181 -0
- data/doc/Renjin/ComplexVector.html +557 -0
- data/doc/Renjin/DataFrame.html +258 -0
- data/doc/Renjin/Environment.html +279 -0
- data/doc/Renjin/Function.html +243 -0
- data/doc/Renjin/Index.html +628 -0
- data/doc/Renjin/List.html +398 -0
- data/doc/Renjin/Logical.html +352 -0
- data/doc/Renjin/Primitive.html +181 -0
- data/doc/Renjin/RBSexp.html +1151 -0
- data/doc/Renjin/RubySexp.html +498 -0
- data/doc/Renjin/Vector.html +3163 -0
- data/doc/RinRuby.html +2079 -0
- data/doc/_index.html +365 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +159 -0
- data/doc/file_list.html +60 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +159 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +939 -0
- data/doc/top-level-namespace.html +679 -0
- data/lib/JRubyR/attributes.rb +5 -2
- data/lib/JRubyR/callback.rb +115 -0
- data/lib/JRubyR/environment.rb +0 -1
- data/lib/JRubyR/indexed.rb +139 -0
- data/lib/JRubyR/list.rb +0 -16
- data/lib/JRubyR/logical_value.rb +0 -1
- data/lib/JRubyR/rbsexp.rb +20 -131
- data/lib/JRubyR/renjin.rb +201 -71
- data/lib/JRubyR/vector.rb +16 -15
- data/lib/scicom.rb +1 -3
- data/target/helper.jar +0 -0
- data/test/test_R_interface.rb +1 -1
- data/test/test_array.rb +1 -1
- data/test/test_assign_mdarray.rb +1 -1
- data/test/test_assign_mdarray_2d.rb +1 -1
- data/test/test_assign_mdarray_3d.rb +1 -1
- data/test/test_attributes.rb +1 -1
- data/test/test_basic.rb +7 -5
- data/test/test_callback.rb +176 -0
- data/test/test_complete.rb +1 -1
- data/test/test_creation.rb +29 -5
- data/test/test_dataframe.rb +1 -1
- data/test/test_factor.rb +1 -1
- data/test/test_functions.rb +13 -10
- data/test/test_linear_model.rb +1 -1
- data/test/test_list.rb +49 -10
- data/test/test_matrix.rb +6 -6
- data/test/test_operators.rb +1 -1
- data/test/test_package.rb +5 -5
- data/test/test_vector.rb +13 -7
- data/vendor/aether-api-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-connector-basic-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-impl-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-spi-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-transport-file-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-transport-http-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-util-1.0.2.v20150114.jar +0 -0
- data/vendor/aopalliance-1.0.jar +0 -0
- data/vendor/asm-3.3.1.jar +0 -0
- data/vendor/asm-5.0.4.jar +0 -0
- data/vendor/asm-commons-5.0.4.jar +0 -0
- data/vendor/asm-tree-5.0.4.jar +0 -0
- data/vendor/asm-util-5.0.4.jar +0 -0
- data/vendor/blas-0.8.jar +0 -0
- data/vendor/cdi-api-1.0.jar +0 -0
- data/vendor/codemodel-2.6.jar +0 -0
- data/vendor/collections-generic-4.01.jar +0 -0
- data/vendor/commons-codec-1.6.jar +0 -0
- data/vendor/commons-compress-1.4.1.jar +0 -0
- data/vendor/commons-logging-1.1.1.jar +0 -0
- data/vendor/commons-math-2.2.jar +0 -0
- data/vendor/commons-vfs2-2.0.jar +0 -0
- data/vendor/datasets-0.8.1891.jar +0 -0
- data/vendor/f2jutil-0.8.jar +0 -0
- data/vendor/gcc-runtime-0.8.1891.jar +0 -0
- data/vendor/grDevices-0.8.1891.jar +0 -0
- data/vendor/graphics-0.8.1891.jar +0 -0
- data/vendor/guava-17.0.jar +0 -0
- data/vendor/httpclient-4.2.6.jar +0 -0
- data/vendor/httpcore-4.2.5.jar +0 -0
- data/vendor/javax.inject-1.jar +0 -0
- data/vendor/jcl-over-slf4j-1.6.2.jar +0 -0
- data/vendor/joda-time-2.0.jar +0 -0
- data/vendor/jsr250-api-1.0.jar +0 -0
- data/vendor/jtransforms-2.4.jar +0 -0
- data/vendor/jung-api-2.0.1.jar +0 -0
- data/vendor/jung-graph-impl-2.0.1.jar +0 -0
- data/vendor/lapack-0.8.jar +0 -0
- data/vendor/maven-aether-provider-3.1.0.jar +0 -0
- data/vendor/maven-model-3.1.0.jar +0 -0
- data/vendor/maven-model-builder-3.1.0.jar +0 -0
- data/vendor/maven-repository-metadata-3.1.0.jar +0 -0
- data/vendor/maven-scm-api-1.4.jar +0 -0
- data/vendor/maven-scm-provider-svn-commons-1.4.jar +0 -0
- data/vendor/maven-scm-provider-svnexe-1.4.jar +0 -0
- data/vendor/maven-settings-3.1.0.jar +0 -0
- data/vendor/maven-settings-builder-3.1.0.jar +0 -0
- data/vendor/methods-0.8.1891.jar +0 -0
- data/vendor/netlib-java-0.9.3-renjin-patched-2.jar +0 -0
- data/vendor/org.eclipse.sisu.inject-0.0.0.M2a.jar +0 -0
- data/vendor/org.eclipse.sisu.plexus-0.0.0.M2a.jar +0 -0
- data/vendor/plexus-cipher-1.4.jar +0 -0
- data/vendor/plexus-classworlds-2.4.jar +0 -0
- data/vendor/plexus-component-annotations-1.5.5.jar +0 -0
- data/vendor/plexus-interpolation-1.16.jar +0 -0
- data/vendor/plexus-sec-dispatcher-1.3.jar +0 -0
- data/vendor/plexus-utils-1.5.6.jar +0 -0
- data/vendor/plexus-utils-3.0.10.jar +0 -0
- data/vendor/regexp-1.3.jar +0 -0
- data/vendor/renjin-aether-package-loader-0.8.1891.jar +0 -0
- data/vendor/renjin-appl-0.8.1891.jar +0 -0
- data/vendor/renjin-core-0.8.1891.jar +0 -0
- data/vendor/renjin-gnur-runtime-0.8.1891.jar +0 -0
- data/vendor/renjin-script-engine-0.8.1891.jar +0 -0
- data/vendor/sisu-guice-3.1.0-no_aop.jar +0 -0
- data/vendor/slf4j-api-1.6.2.jar +0 -0
- data/vendor/stats-0.8.1891.jar +0 -0
- data/vendor/utils-0.8.1891.jar +0 -0
- data/vendor/xerbla-0.8.jar +0 -0
- data/vendor/xz-1.0.jar +0 -0
- data/version.rb +1 -1
- metadata +229 -127
- data/cran/AppliedPredictiveModeling.jar +0 -0
- data/cran/AppliedPredictiveModeling.xml +0 -25
- data/cran/AssetPricing.jar +0 -0
- data/cran/AssetPricing.xml +0 -25
- data/lib/env.rb +0 -12
- data/lib/rinruby.rb +0 -795
- data/test/env.rb +0 -2
- data/test/test_tmp.rb +0 -67
- data/vendor/Renjin.pdf +0 -0
- data/vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar +0 -0
data/doc/RinRuby.html
ADDED
|
@@ -0,0 +1,2079 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
6
|
+
<title>
|
|
7
|
+
Class: RinRuby
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.8.7.6
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
|
19
|
+
relpath = '';
|
|
20
|
+
framesUrl = "frames.html#!RinRuby.html";
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
25
|
+
|
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<div id="header">
|
|
32
|
+
<div id="menu">
|
|
33
|
+
|
|
34
|
+
<a href="_index.html">Index (R)</a> »
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<span class="title">RinRuby</span>
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div id="search">
|
|
44
|
+
|
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
|
46
|
+
href="class_list.html">
|
|
47
|
+
Class List
|
|
48
|
+
</a>
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
|
51
|
+
href="method_list.html">
|
|
52
|
+
Method List
|
|
53
|
+
</a>
|
|
54
|
+
|
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
|
56
|
+
href="file_list.html">
|
|
57
|
+
File List
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<iframe id="search_frame"></iframe>
|
|
65
|
+
|
|
66
|
+
<div id="content"><h1>Class: RinRuby
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
</h1>
|
|
71
|
+
|
|
72
|
+
<dl class="box">
|
|
73
|
+
|
|
74
|
+
<dt class="r1">Inherits:</dt>
|
|
75
|
+
<dd class="r1">
|
|
76
|
+
<span class="inheritName">Object</span>
|
|
77
|
+
|
|
78
|
+
<ul class="fullTree">
|
|
79
|
+
<li>Object</li>
|
|
80
|
+
|
|
81
|
+
<li class="next">RinRuby</li>
|
|
82
|
+
|
|
83
|
+
</ul>
|
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
|
85
|
+
|
|
86
|
+
</dd>
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<dt class="r2 last">Defined in:</dt>
|
|
97
|
+
<dd class="r2 last">lib/rinruby.rb</dd>
|
|
98
|
+
|
|
99
|
+
</dl>
|
|
100
|
+
<div class="clear"></div>
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
<h2>Constant Summary</h2>
|
|
104
|
+
|
|
105
|
+
<dl class="constants">
|
|
106
|
+
|
|
107
|
+
<dt id="VERSION-constant" class="">VERSION =
|
|
108
|
+
|
|
109
|
+
</dt>
|
|
110
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2.0.1</span><span class='tstring_end'>'</span></span></pre></dd>
|
|
111
|
+
|
|
112
|
+
<dt id="EngineClosed-constant" class="">EngineClosed =
|
|
113
|
+
<div class="docstring">
|
|
114
|
+
<div class="discussion">
|
|
115
|
+
|
|
116
|
+
<p>Exception for closed engine</p>
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
<div class="tags">
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
</div>
|
|
125
|
+
</dt>
|
|
126
|
+
<dd><pre class="code"><span class='const'>Class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span></pre></dd>
|
|
127
|
+
|
|
128
|
+
<dt id="ParseError-constant" class="">ParseError =
|
|
129
|
+
<div class="docstring">
|
|
130
|
+
<div class="discussion">
|
|
131
|
+
|
|
132
|
+
<p>Parse error</p>
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
<div class="tags">
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
</div>
|
|
141
|
+
</dt>
|
|
142
|
+
<dd><pre class="code"><span class='const'>Class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span></pre></dd>
|
|
143
|
+
|
|
144
|
+
</dl>
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
|
|
151
|
+
<ul class="summary">
|
|
152
|
+
|
|
153
|
+
<li class="public ">
|
|
154
|
+
<span class="summary_signature">
|
|
155
|
+
|
|
156
|
+
<a href="#echo_enabled-instance_method" title="#echo_enabled (instance method)">- (Object) <strong>echo_enabled</strong> </a>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
</span>
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
<span class="note title readonly">readonly</span>
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
<span class="summary_desc"><div class='inline'>
|
|
176
|
+
<p>RinRuby is invoked within a Ruby script (or the interactive "irb" prompt
|
|
177
|
+
denoted >>) using:.</p>
|
|
178
|
+
</div></span>
|
|
179
|
+
|
|
180
|
+
</li>
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
<li class="public ">
|
|
184
|
+
<span class="summary_signature">
|
|
185
|
+
|
|
186
|
+
<a href="#executable-instance_method" title="#executable (instance method)">- (Object) <strong>executable</strong> </a>
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
</span>
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
<span class="note title readonly">readonly</span>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
<span class="summary_desc"><div class='inline'>
|
|
206
|
+
<p>Returns the value of attribute executable.</p>
|
|
207
|
+
</div></span>
|
|
208
|
+
|
|
209
|
+
</li>
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
<li class="public ">
|
|
213
|
+
<span class="summary_signature">
|
|
214
|
+
|
|
215
|
+
<a href="#hostname-instance_method" title="#hostname (instance method)">- (Object) <strong>hostname</strong> </a>
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
</span>
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
<span class="note title readonly">readonly</span>
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
<span class="summary_desc"><div class='inline'>
|
|
235
|
+
<p>Returns the value of attribute hostname.</p>
|
|
236
|
+
</div></span>
|
|
237
|
+
|
|
238
|
+
</li>
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
<li class="public ">
|
|
242
|
+
<span class="summary_signature">
|
|
243
|
+
|
|
244
|
+
<a href="#interactive-instance_method" title="#interactive (instance method)">- (Object) <strong>interactive</strong> </a>
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
</span>
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
<span class="note title readonly">readonly</span>
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
<span class="summary_desc"><div class='inline'>
|
|
264
|
+
<p>Returns the value of attribute interactive.</p>
|
|
265
|
+
</div></span>
|
|
266
|
+
|
|
267
|
+
</li>
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
<li class="public ">
|
|
271
|
+
<span class="summary_signature">
|
|
272
|
+
|
|
273
|
+
<a href="#port_number-instance_method" title="#port_number (instance method)">- (Object) <strong>port_number</strong> </a>
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
</span>
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
<span class="note title readonly">readonly</span>
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
<span class="summary_desc"><div class='inline'>
|
|
293
|
+
<p>Returns the value of attribute port_number.</p>
|
|
294
|
+
</div></span>
|
|
295
|
+
|
|
296
|
+
</li>
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
<li class="public ">
|
|
300
|
+
<span class="summary_signature">
|
|
301
|
+
|
|
302
|
+
<a href="#port_width-instance_method" title="#port_width (instance method)">- (Object) <strong>port_width</strong> </a>
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
</span>
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
<span class="note title readonly">readonly</span>
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
<span class="summary_desc"><div class='inline'>
|
|
322
|
+
<p>Returns the value of attribute port_width.</p>
|
|
323
|
+
</div></span>
|
|
324
|
+
|
|
325
|
+
</li>
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
<li class="public ">
|
|
329
|
+
<span class="summary_signature">
|
|
330
|
+
|
|
331
|
+
<a href="#readline-instance_method" title="#readline (instance method)">- (Object) <strong>readline</strong> </a>
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
</span>
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
<span class="note title readonly">readonly</span>
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
<span class="summary_desc"><div class='inline'>
|
|
351
|
+
<p>Returns the value of attribute readline.</p>
|
|
352
|
+
</div></span>
|
|
353
|
+
|
|
354
|
+
</li>
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
</ul>
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
<h2>
|
|
364
|
+
Instance Method Summary
|
|
365
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
|
366
|
+
</h2>
|
|
367
|
+
|
|
368
|
+
<ul class="summary">
|
|
369
|
+
|
|
370
|
+
<li class="public ">
|
|
371
|
+
<span class="summary_signature">
|
|
372
|
+
|
|
373
|
+
<a href="#assign-instance_method" title="#assign (instance method)">- (Object) <strong>assign</strong>(name, value) </a>
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
</span>
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
<span class="summary_desc"><div class='inline'>
|
|
388
|
+
<p>Data is copied from Ruby to R using the assign method or a short-hand
|
|
389
|
+
equivalent.</p>
|
|
390
|
+
</div></span>
|
|
391
|
+
|
|
392
|
+
</li>
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
<li class="public ">
|
|
396
|
+
<span class="summary_signature">
|
|
397
|
+
|
|
398
|
+
<a href="#complete%3F-instance_method" title="#complete? (instance method)">- (Boolean) <strong>complete?</strong>(string) </a>
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
</span>
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
|
413
|
+
|
|
414
|
+
</li>
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
<li class="public ">
|
|
418
|
+
<span class="summary_signature">
|
|
419
|
+
|
|
420
|
+
<a href="#echo-instance_method" title="#echo (instance method)">- (Object) <strong>echo</strong>(enable = nil, stderr = nil) </a>
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
</span>
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
<span class="summary_desc"><div class='inline'>
|
|
435
|
+
<p>The echo method controls whether the eval method displays output from R
|
|
436
|
+
and, if echo is enabled, whether messages, warnings, and errors from stderr
|
|
437
|
+
are also displayed.</p>
|
|
438
|
+
</div></span>
|
|
439
|
+
|
|
440
|
+
</li>
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
<li class="public ">
|
|
444
|
+
<span class="summary_signature">
|
|
445
|
+
|
|
446
|
+
<a href="#eval-instance_method" title="#eval (instance method)">- (Object) <strong>eval</strong>(string, echo_override = nil) </a>
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
</span>
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
<span class="summary_desc"><div class='inline'>
|
|
461
|
+
<p>The eval instance method passes the R commands contained in the supplied
|
|
462
|
+
string and displays any resulting plots or prints the output.</p>
|
|
463
|
+
</div></span>
|
|
464
|
+
|
|
465
|
+
</li>
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
<li class="public ">
|
|
469
|
+
<span class="summary_signature">
|
|
470
|
+
|
|
471
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (RinRuby) <strong>initialize</strong>(*args) </a>
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
</span>
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
<span class="note title constructor">constructor</span>
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
<span class="summary_desc"><div class='inline'>
|
|
488
|
+
<p>A new instance of RinRuby.</p>
|
|
489
|
+
</div></span>
|
|
490
|
+
|
|
491
|
+
</li>
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
<li class="public ">
|
|
495
|
+
<span class="summary_signature">
|
|
496
|
+
|
|
497
|
+
<a href="#method_missing-instance_method" title="#method_missing (instance method)">- (Object) <strong>method_missing</strong>(symbol, *args) </a>
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
</span>
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
<span class="summary_desc"><div class='inline'>
|
|
512
|
+
<p>If a method is called which is not defined, then it is assumed that the
|
|
513
|
+
user is attempting to either pull or assign a variable to R.</p>
|
|
514
|
+
</div></span>
|
|
515
|
+
|
|
516
|
+
</li>
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
<li class="public ">
|
|
520
|
+
<span class="summary_signature">
|
|
521
|
+
|
|
522
|
+
<a href="#prompt-instance_method" title="#prompt (instance method)">- (Object) <strong>prompt</strong>(regular_prompt = "> ", continue_prompt = "+ ") </a>
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
</span>
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
<span class="summary_desc"><div class='inline'>
|
|
537
|
+
<p>When sending code to Ruby using an interactive prompt, this method will
|
|
538
|
+
change the prompt to an R prompt.</p>
|
|
539
|
+
</div></span>
|
|
540
|
+
|
|
541
|
+
</li>
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
<li class="public ">
|
|
545
|
+
<span class="summary_signature">
|
|
546
|
+
|
|
547
|
+
<a href="#pull-instance_method" title="#pull (instance method)">- (Object) <strong>pull</strong>(string, singletons = false) </a>
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
</span>
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
<span class="summary_desc"><div class='inline'>
|
|
562
|
+
<p>Data is copied from R to Ruby using the pull method or a short-hand
|
|
563
|
+
equivalent.</p>
|
|
564
|
+
</div></span>
|
|
565
|
+
|
|
566
|
+
</li>
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
<li class="public ">
|
|
570
|
+
<span class="summary_signature">
|
|
571
|
+
|
|
572
|
+
<a href="#quit-instance_method" title="#quit (instance method)">- (Object) <strong>quit</strong> </a>
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
</span>
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
<span class="summary_desc"><div class='inline'>
|
|
587
|
+
<p>The quit method will properly close the bridge between Ruby and R, freeing
|
|
588
|
+
up system resources.</p>
|
|
589
|
+
</div></span>
|
|
590
|
+
|
|
591
|
+
</li>
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
</ul>
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
<div id="constructor_details" class="method_details_list">
|
|
598
|
+
<h2>Constructor Details</h2>
|
|
599
|
+
|
|
600
|
+
<div class="method_details first">
|
|
601
|
+
<h3 class="signature first" id="initialize-instance_method">
|
|
602
|
+
|
|
603
|
+
- (<tt><span class='object_link'><a href="" title="RinRuby (class)">RinRuby</a></span></tt>) <strong>initialize</strong>(*args)
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
</h3><div class="docstring">
|
|
610
|
+
<div class="discussion">
|
|
611
|
+
|
|
612
|
+
<p>Returns a new instance of RinRuby</p>
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
</div>
|
|
616
|
+
</div>
|
|
617
|
+
<div class="tags">
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
</div><table class="source_code">
|
|
621
|
+
<tr>
|
|
622
|
+
<td>
|
|
623
|
+
<pre class="lines">
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
108
|
|
627
|
+
109
|
|
628
|
+
110
|
|
629
|
+
111
|
|
630
|
+
112
|
|
631
|
+
113
|
|
632
|
+
114
|
|
633
|
+
115
|
|
634
|
+
116
|
|
635
|
+
117
|
|
636
|
+
118
|
|
637
|
+
119
|
|
638
|
+
120
|
|
639
|
+
121
|
|
640
|
+
122
|
|
641
|
+
123
|
|
642
|
+
124
|
|
643
|
+
125
|
|
644
|
+
126
|
|
645
|
+
127
|
|
646
|
+
128
|
|
647
|
+
129
|
|
648
|
+
130
|
|
649
|
+
131
|
|
650
|
+
132
|
|
651
|
+
133
|
|
652
|
+
134
|
|
653
|
+
135
|
|
654
|
+
136
|
|
655
|
+
137
|
|
656
|
+
138
|
|
657
|
+
139
|
|
658
|
+
140
|
|
659
|
+
141
|
|
660
|
+
142
|
|
661
|
+
143
|
|
662
|
+
144
|
|
663
|
+
145
|
|
664
|
+
146
|
|
665
|
+
147
|
|
666
|
+
148
|
|
667
|
+
149
|
|
668
|
+
150
|
|
669
|
+
151
|
|
670
|
+
152
|
|
671
|
+
153
|
|
672
|
+
154
|
|
673
|
+
155
|
|
674
|
+
156
|
|
675
|
+
157
|
|
676
|
+
158
|
|
677
|
+
159
|
|
678
|
+
160
|
|
679
|
+
161
|
|
680
|
+
162
|
|
681
|
+
163
|
|
682
|
+
164
|
|
683
|
+
165
|
|
684
|
+
166
|
|
685
|
+
167
|
|
686
|
+
168
|
|
687
|
+
169
|
|
688
|
+
170
|
|
689
|
+
171
|
|
690
|
+
172
|
|
691
|
+
173
|
|
692
|
+
174
|
|
693
|
+
175
|
|
694
|
+
176
|
|
695
|
+
177
|
|
696
|
+
178
|
|
697
|
+
179
|
|
698
|
+
180
|
|
699
|
+
181
|
|
700
|
+
182
|
|
701
|
+
183
|
|
702
|
+
184
|
|
703
|
+
185
|
|
704
|
+
186
|
|
705
|
+
187</pre>
|
|
706
|
+
</td>
|
|
707
|
+
<td>
|
|
708
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 108</span>
|
|
709
|
+
|
|
710
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
|
711
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
|
712
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>==</span><span class='int'>1</span> <span class='kw'>and</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Hash</span>
|
|
713
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
|
714
|
+
<span class='kw'>else</span>
|
|
715
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:echo</span><span class='rbracket'>]</span><span class='op'>=</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>==</span><span class='int'>0</span>
|
|
716
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:interactive</span><span class='rbracket'>]</span><span class='op'>=</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>==</span><span class='int'>0</span>
|
|
717
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:executable</span><span class='rbracket'>]</span><span class='op'>=</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>==</span><span class='int'>0</span>
|
|
718
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:port_number</span><span class='rbracket'>]</span><span class='op'>=</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>==</span><span class='int'>0</span>
|
|
719
|
+
<span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:port_width</span><span class='rbracket'>]</span><span class='op'>=</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>==</span><span class='int'>0</span>
|
|
720
|
+
<span class='kw'>end</span>
|
|
721
|
+
<span class='id identifier rubyid_default_opts'>default_opts</span><span class='op'>=</span> <span class='lbrace'>{</span><span class='symbol'>:echo</span><span class='op'>=></span><span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:interactive</span><span class='op'>=></span><span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:executable</span><span class='op'>=></span><span class='kw'>nil</span><span class='comma'>,</span> <span class='symbol'>:port_number</span><span class='op'>=></span><span class='int'>38442</span><span class='comma'>,</span> <span class='symbol'>:port_width</span><span class='op'>=></span><span class='int'>1000</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='op'>=></span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>'</span></span><span class='rbrace'>}</span>
|
|
722
|
+
|
|
723
|
+
<span class='ivar'>@opts</span><span class='op'>=</span><span class='id identifier rubyid_default_opts'>default_opts</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='rparen'>)</span>
|
|
724
|
+
<span class='ivar'>@port_width</span><span class='op'>=</span><span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:port_width</span><span class='rbracket'>]</span>
|
|
725
|
+
<span class='ivar'>@executable</span><span class='op'>=</span><span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:executable</span><span class='rbracket'>]</span>
|
|
726
|
+
<span class='ivar'>@hostname</span><span class='op'>=</span><span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:hostname</span><span class='rbracket'>]</span>
|
|
727
|
+
<span class='kw'>while</span> <span class='kw'>true</span>
|
|
728
|
+
<span class='kw'>begin</span>
|
|
729
|
+
<span class='ivar'>@port_number</span> <span class='op'>=</span> <span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:port_number</span><span class='rbracket'>]</span> <span class='op'>+</span> <span class='id identifier rubyid_rand'>rand</span><span class='lparen'>(</span><span class='id identifier rubyid_port_width'>port_width</span><span class='rparen'>)</span>
|
|
730
|
+
<span class='ivar'>@server_socket</span> <span class='op'>=</span> <span class='const'>TCPServer</span><span class='op'>::</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='ivar'>@hostname</span><span class='comma'>,</span> <span class='ivar'>@port_number</span><span class='rparen'>)</span>
|
|
731
|
+
<span class='kw'>break</span>
|
|
732
|
+
<span class='kw'>rescue</span> <span class='const'>Errno</span><span class='op'>::</span><span class='const'>EADDRINUSE</span>
|
|
733
|
+
<span class='id identifier rubyid_sleep'>sleep</span> <span class='float'>0.5</span> <span class='kw'>if</span> <span class='id identifier rubyid_port_width'>port_width</span> <span class='op'>==</span> <span class='int'>1</span>
|
|
734
|
+
<span class='kw'>end</span>
|
|
735
|
+
<span class='kw'>end</span>
|
|
736
|
+
<span class='ivar'>@echo_enabled</span> <span class='op'>=</span> <span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:echo</span><span class='rbracket'>]</span>
|
|
737
|
+
<span class='ivar'>@echo_stderr</span> <span class='op'>=</span> <span class='kw'>false</span>
|
|
738
|
+
<span class='ivar'>@interactive</span> <span class='op'>=</span> <span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:interactive</span><span class='rbracket'>]</span>
|
|
739
|
+
<span class='ivar'>@platform</span> <span class='op'>=</span> <span class='kw'>case</span> <span class='const'>RUBY_PLATFORM</span>
|
|
740
|
+
<span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>mswin</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>windows</span><span class='tstring_end'>'</span></span>
|
|
741
|
+
<span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>mingw</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>windows</span><span class='tstring_end'>'</span></span>
|
|
742
|
+
<span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>bccwin</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>windows</span><span class='tstring_end'>'</span></span>
|
|
743
|
+
<span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>cygwin</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>windows-cygwin</span><span class='tstring_end'>'</span></span>
|
|
744
|
+
<span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>java</span><span class='regexp_end'>/</span></span>
|
|
745
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>java</span><span class='tstring_end'>'</span></span> <span class='comment'>#:nodoc:
|
|
746
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_java'>java</span><span class='period'>.</span><span class='id identifier rubyid_lang'>lang</span><span class='period'>.</span><span class='const'>System</span><span class='period'>.</span><span class='id identifier rubyid_getProperty'>getProperty</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>os.name</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>[Ww]indows</span><span class='regexp_end'>/</span></span>
|
|
747
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>windows-java</span><span class='tstring_end'>'</span></span>
|
|
748
|
+
<span class='kw'>else</span>
|
|
749
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>default-java</span><span class='tstring_end'>'</span></span>
|
|
750
|
+
<span class='kw'>end</span>
|
|
751
|
+
<span class='kw'>else</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>default</span><span class='tstring_end'>'</span></span>
|
|
752
|
+
<span class='kw'>end</span>
|
|
753
|
+
<span class='kw'>if</span> <span class='ivar'>@executable</span> <span class='op'>==</span> <span class='kw'>nil</span>
|
|
754
|
+
<span class='ivar'>@executable</span> <span class='op'>=</span> <span class='lparen'>(</span> <span class='ivar'>@platform</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>windows</span><span class='regexp_end'>/</span></span> <span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_find_R_on_windows'>find_R_on_windows</span><span class='lparen'>(</span><span class='ivar'>@platform</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>cygwin</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>R</span><span class='tstring_end'>'</span></span>
|
|
755
|
+
<span class='kw'>end</span>
|
|
756
|
+
<span class='id identifier rubyid_platform_options'>platform_options</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
757
|
+
<span class='kw'>if</span> <span class='lparen'>(</span> <span class='ivar'>@interactive</span> <span class='rparen'>)</span>
|
|
758
|
+
<span class='kw'>begin</span>
|
|
759
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>readline</span><span class='tstring_end'>'</span></span>
|
|
760
|
+
<span class='kw'>rescue</span> <span class='const'>LoadError</span>
|
|
761
|
+
<span class='kw'>end</span>
|
|
762
|
+
<span class='ivar'>@readline</span> <span class='op'>=</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='const'>Readline</span><span class='rparen'>)</span>
|
|
763
|
+
<span class='id identifier rubyid_platform_options'>platform_options</span> <span class='op'><<</span> <span class='lparen'>(</span> <span class='lparen'>(</span> <span class='ivar'>@platform</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>windows</span><span class='regexp_end'>/</span></span> <span class='rparen'>)</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>--ess</span><span class='tstring_end'>'</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>--interactive</span><span class='tstring_end'>'</span></span> <span class='rparen'>)</span>
|
|
764
|
+
<span class='kw'>else</span>
|
|
765
|
+
<span class='ivar'>@readline</span> <span class='op'>=</span> <span class='kw'>false</span>
|
|
766
|
+
<span class='kw'>end</span>
|
|
767
|
+
<span class='id identifier rubyid_cmd'>cmd</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>%Q<</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_executable'>executable</span><span class='rbrace'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform_options'>platform_options</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> </span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rbrace'>}</span><span class='tstring_content'> --slave</span><span class='tstring_end'>></span></span>
|
|
768
|
+
<span class='ivar'>@engine</span> <span class='op'>=</span> <span class='const'>IO</span><span class='period'>.</span><span class='id identifier rubyid_popen'>popen</span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>w+</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
769
|
+
<span class='ivar'>@reader</span> <span class='op'>=</span> <span class='ivar'>@engine</span>
|
|
770
|
+
<span class='ivar'>@writer</span> <span class='op'>=</span> <span class='ivar'>@engine</span>
|
|
771
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Engine closed</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
|
772
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='heredoc_beg'><<-EOF</span>
|
|
773
|
+
<span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_KeepTrying_Variable</span><span class='rbrace'>}</span><span class='tstring_content'> <- TRUE
|
|
774
|
+
while ( </span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_KeepTrying_Variable</span><span class='rbrace'>}</span><span class='tstring_content'> ) {
|
|
775
|
+
</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Socket</span><span class='rbrace'>}</span><span class='tstring_content'> <- try(suppressWarnings(socketConnection("</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='rbrace'>}</span><span class='tstring_content'>", </span><span class='embexpr_beg'>#{</span><span class='ivar'>@port_number</span><span class='rbrace'>}</span><span class='tstring_content'>, blocking=TRUE, open="rb")),TRUE)
|
|
776
|
+
if ( inherits(</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Socket</span><span class='rbrace'>}</span><span class='tstring_content'>,"try-error") ) {
|
|
777
|
+
Sys.sleep(0.1)
|
|
778
|
+
} else {
|
|
779
|
+
</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_KeepTrying_Variable</span><span class='rbrace'>}</span><span class='tstring_content'> <- FALSE
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
rm(</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_KeepTrying_Variable</span><span class='rbrace'>}</span><span class='tstring_content'>)
|
|
783
|
+
</span><span class='heredoc_end'> EOF
|
|
784
|
+
</span> <span class='id identifier rubyid_r_rinruby_get_value'>r_rinruby_get_value</span>
|
|
785
|
+
<span class='id identifier rubyid_r_rinruby_pull'>r_rinruby_pull</span>
|
|
786
|
+
<span class='id identifier rubyid_r_rinruby_parseable'>r_rinruby_parseable</span>
|
|
787
|
+
<span class='ivar'>@socket</span> <span class='op'>=</span> <span class='ivar'>@server_socket</span><span class='period'>.</span><span class='id identifier rubyid_accept'>accept</span>
|
|
788
|
+
<span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='comma'>,</span><span class='kw'>true</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@platform</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.*-java</span><span class='regexp_end'>/</span></span> <span class='comment'># Redirect error messages on the Java platform
|
|
789
|
+
</span><span class='kw'>end</span></pre>
|
|
790
|
+
</td>
|
|
791
|
+
</tr>
|
|
792
|
+
</table>
|
|
793
|
+
</div>
|
|
794
|
+
|
|
795
|
+
</div>
|
|
796
|
+
<div id="method_missing_details" class="method_details_list">
|
|
797
|
+
<h2>Dynamic Method Handling</h2>
|
|
798
|
+
<p class="notice this">
|
|
799
|
+
This class handles dynamic methods through the <tt>method_missing</tt> method
|
|
800
|
+
|
|
801
|
+
</p>
|
|
802
|
+
|
|
803
|
+
<div class="method_details first">
|
|
804
|
+
<h3 class="signature first" id="method_missing-instance_method">
|
|
805
|
+
|
|
806
|
+
- (<tt>Object</tt>) <strong>method_missing</strong>(symbol, *args)
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
</h3><div class="docstring">
|
|
813
|
+
<div class="discussion">
|
|
814
|
+
|
|
815
|
+
<p>If a method is called which is not defined, then it is assumed that the
|
|
816
|
+
user is attempting to either pull or assign a variable to R. This allows
|
|
817
|
+
for the short-hand equivalents to the pull and assign methods. For
|
|
818
|
+
example:</p>
|
|
819
|
+
|
|
820
|
+
<pre class="code ruby"><code class="ruby">>> R.x = 2</code></pre>
|
|
821
|
+
|
|
822
|
+
<p>is the same as:</p>
|
|
823
|
+
|
|
824
|
+
<pre class="code ruby"><code class="ruby">>> R.assign("x",2)</code></pre>
|
|
825
|
+
|
|
826
|
+
<p>Also:</p>
|
|
827
|
+
|
|
828
|
+
<pre class="code ruby"><code class="ruby">>> n = R.x</code></pre>
|
|
829
|
+
|
|
830
|
+
<p>is the same as:</p>
|
|
831
|
+
|
|
832
|
+
<pre class="code ruby"><code class="ruby">>> n = R.pull("x")</code></pre>
|
|
833
|
+
|
|
834
|
+
<p>The parameters passed to method_missing are those used for the pull or
|
|
835
|
+
assign depending on the context.</p>
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
</div>
|
|
839
|
+
</div>
|
|
840
|
+
<div class="tags">
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
</div><table class="source_code">
|
|
844
|
+
<tr>
|
|
845
|
+
<td>
|
|
846
|
+
<pre class="lines">
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
356
|
|
850
|
+
357
|
|
851
|
+
358
|
|
852
|
+
359
|
|
853
|
+
360
|
|
854
|
+
361
|
|
855
|
+
362
|
|
856
|
+
363
|
|
857
|
+
364
|
|
858
|
+
365
|
|
859
|
+
366</pre>
|
|
860
|
+
</td>
|
|
861
|
+
<td>
|
|
862
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 356</span>
|
|
863
|
+
|
|
864
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
|
865
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_id2name'>id2name</span>
|
|
866
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.*)=$</span><span class='regexp_end'>/</span></span>
|
|
867
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>You shouldn't assign nil</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='op'>==</span><span class='lbracket'>[</span><span class='kw'>nil</span><span class='rbracket'>]</span>
|
|
868
|
+
<span class='kw'>super</span> <span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>!=</span> <span class='int'>1</span>
|
|
869
|
+
<span class='id identifier rubyid_assign'>assign</span><span class='lparen'>(</span><span class='backref'>$1</span><span class='comma'>,</span><span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
|
870
|
+
<span class='kw'>else</span>
|
|
871
|
+
<span class='kw'>super</span> <span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>!=</span> <span class='int'>0</span>
|
|
872
|
+
<span class='id identifier rubyid_pull'>pull</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
|
873
|
+
<span class='kw'>end</span>
|
|
874
|
+
<span class='kw'>end</span></pre>
|
|
875
|
+
</td>
|
|
876
|
+
</tr>
|
|
877
|
+
</table>
|
|
878
|
+
</div>
|
|
879
|
+
|
|
880
|
+
</div>
|
|
881
|
+
|
|
882
|
+
<div id="instance_attr_details" class="attr_details">
|
|
883
|
+
<h2>Instance Attribute Details</h2>
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
<span id=""></span>
|
|
887
|
+
<div class="method_details first">
|
|
888
|
+
<h3 class="signature first" id="echo_enabled-instance_method">
|
|
889
|
+
|
|
890
|
+
- (<tt>Object</tt>) <strong>echo_enabled</strong> <span class="extras">(readonly)</span>
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
</h3><div class="docstring">
|
|
897
|
+
<div class="discussion">
|
|
898
|
+
|
|
899
|
+
<p>RinRuby is invoked within a Ruby script (or the interactive "irb" prompt
|
|
900
|
+
denoted >>) using:</p>
|
|
901
|
+
|
|
902
|
+
<pre class="code ruby"><code class="ruby">>> require "rinruby"
|
|
903
|
+
</code></pre>
|
|
904
|
+
|
|
905
|
+
<p>The previous statement reads the definition of the RinRuby class into the
|
|
906
|
+
current Ruby interpreter and creates an instance of the RinRuby class named
|
|
907
|
+
R. There is a second method for starting an instance of R which allows the
|
|
908
|
+
user to use any name for the instance, in this case myr:</p>
|
|
909
|
+
|
|
910
|
+
<pre class="code ruby"><code class="ruby">>> require "rinruby"
|
|
911
|
+
>> myr = RinRuby.new
|
|
912
|
+
>> myr.eval "rnorm(1)"
|
|
913
|
+
</code></pre>
|
|
914
|
+
|
|
915
|
+
<p>Any number of independent instances of R can be created in this way.</p>
|
|
916
|
+
|
|
917
|
+
<p><strong>Parameters that can be passed to the new method using a
|
|
918
|
+
Hash:</strong></p>
|
|
919
|
+
<ul><li>
|
|
920
|
+
<p>:echo: By setting the echo to false, output from R is suppressed, although
|
|
921
|
+
warnings are still printed. This option can be changed later by using the
|
|
922
|
+
echo method. The default is true.</p>
|
|
923
|
+
</li><li>
|
|
924
|
+
<p>:interactive: When interactive is false, R is run in non-interactive mode,
|
|
925
|
+
resulting in plots without an explicit device being written to Rplots.pdf.
|
|
926
|
+
Otherwise (i.e., interactive is true), plots are shown on the screen. The
|
|
927
|
+
default is true.</p>
|
|
928
|
+
</li><li>
|
|
929
|
+
<p>:executable: The path of the R executable (which is "R" in Linux and Mac OS
|
|
930
|
+
X, or "Rterm.exe" in Windows) can be set with the executable argument. The
|
|
931
|
+
default is nil which makes RinRuby use the registry keys to find the path
|
|
932
|
+
(on Windows) or use the path defined by $PATH (on Linux and Mac OS X).</p>
|
|
933
|
+
</li><li>
|
|
934
|
+
<p>:port_number: This is the smallest port number on the local host that could
|
|
935
|
+
be used to pass data between Ruby and R. The actual port number used
|
|
936
|
+
depends on port_width.</p>
|
|
937
|
+
</li><li>
|
|
938
|
+
<p>:port_width: RinRuby will randomly select a uniform number between
|
|
939
|
+
port_number and port_number + port_width - 1 (inclusive) to pass data
|
|
940
|
+
between Ruby and R. If the randomly selected port is not available, RinRuby
|
|
941
|
+
will continue selecting random ports until it finds one that is available.
|
|
942
|
+
By setting port_width to 1, RinRuby will wait until port_number is
|
|
943
|
+
available. The default port_width is 1000.</p>
|
|
944
|
+
</li></ul>
|
|
945
|
+
|
|
946
|
+
<p>It may be desirable to change the parameters to the instance of R, but
|
|
947
|
+
still call it by the name of R. In that case the old instance of R which
|
|
948
|
+
was created with the 'require "rinruby"' statement should be closed first
|
|
949
|
+
using the quit method which is explained below. Unless the previous
|
|
950
|
+
instance is killed, it will continue to use system resources until exiting
|
|
951
|
+
Ruby. The following shows an example by changing the parameter echo:</p>
|
|
952
|
+
|
|
953
|
+
<pre class="code ruby"><code class="ruby">>> require "rinruby"
|
|
954
|
+
>> R.quit
|
|
955
|
+
>> R = RinRuby.new(false)
|
|
956
|
+
</code></pre>
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
</div>
|
|
960
|
+
</div>
|
|
961
|
+
<div class="tags">
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
</div><table class="source_code">
|
|
965
|
+
<tr>
|
|
966
|
+
<td>
|
|
967
|
+
<pre class="lines">
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
102
|
|
971
|
+
103
|
|
972
|
+
104</pre>
|
|
973
|
+
</td>
|
|
974
|
+
<td>
|
|
975
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 102</span>
|
|
976
|
+
|
|
977
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_echo_enabled'>echo_enabled</span>
|
|
978
|
+
<span class='ivar'>@echo_enabled</span>
|
|
979
|
+
<span class='kw'>end</span></pre>
|
|
980
|
+
</td>
|
|
981
|
+
</tr>
|
|
982
|
+
</table>
|
|
983
|
+
</div>
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
<span id=""></span>
|
|
987
|
+
<div class="method_details ">
|
|
988
|
+
<h3 class="signature " id="executable-instance_method">
|
|
989
|
+
|
|
990
|
+
- (<tt>Object</tt>) <strong>executable</strong> <span class="extras">(readonly)</span>
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
</h3><div class="docstring">
|
|
997
|
+
<div class="discussion">
|
|
998
|
+
|
|
999
|
+
<p>Returns the value of attribute executable</p>
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
</div>
|
|
1003
|
+
</div>
|
|
1004
|
+
<div class="tags">
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
</div><table class="source_code">
|
|
1008
|
+
<tr>
|
|
1009
|
+
<td>
|
|
1010
|
+
<pre class="lines">
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
103
|
|
1014
|
+
104
|
|
1015
|
+
105</pre>
|
|
1016
|
+
</td>
|
|
1017
|
+
<td>
|
|
1018
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 103</span>
|
|
1019
|
+
|
|
1020
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_executable'>executable</span>
|
|
1021
|
+
<span class='ivar'>@executable</span>
|
|
1022
|
+
<span class='kw'>end</span></pre>
|
|
1023
|
+
</td>
|
|
1024
|
+
</tr>
|
|
1025
|
+
</table>
|
|
1026
|
+
</div>
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
<span id=""></span>
|
|
1030
|
+
<div class="method_details ">
|
|
1031
|
+
<h3 class="signature " id="hostname-instance_method">
|
|
1032
|
+
|
|
1033
|
+
- (<tt>Object</tt>) <strong>hostname</strong> <span class="extras">(readonly)</span>
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
</h3><div class="docstring">
|
|
1040
|
+
<div class="discussion">
|
|
1041
|
+
|
|
1042
|
+
<p>Returns the value of attribute hostname</p>
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
</div>
|
|
1046
|
+
</div>
|
|
1047
|
+
<div class="tags">
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
</div><table class="source_code">
|
|
1051
|
+
<tr>
|
|
1052
|
+
<td>
|
|
1053
|
+
<pre class="lines">
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
106
|
|
1057
|
+
107
|
|
1058
|
+
108</pre>
|
|
1059
|
+
</td>
|
|
1060
|
+
<td>
|
|
1061
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 106</span>
|
|
1062
|
+
|
|
1063
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_hostname'>hostname</span>
|
|
1064
|
+
<span class='ivar'>@hostname</span>
|
|
1065
|
+
<span class='kw'>end</span></pre>
|
|
1066
|
+
</td>
|
|
1067
|
+
</tr>
|
|
1068
|
+
</table>
|
|
1069
|
+
</div>
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
<span id=""></span>
|
|
1073
|
+
<div class="method_details ">
|
|
1074
|
+
<h3 class="signature " id="interactive-instance_method">
|
|
1075
|
+
|
|
1076
|
+
- (<tt>Object</tt>) <strong>interactive</strong> <span class="extras">(readonly)</span>
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
</h3><div class="docstring">
|
|
1083
|
+
<div class="discussion">
|
|
1084
|
+
|
|
1085
|
+
<p>Returns the value of attribute interactive</p>
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
</div>
|
|
1089
|
+
</div>
|
|
1090
|
+
<div class="tags">
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
</div><table class="source_code">
|
|
1094
|
+
<tr>
|
|
1095
|
+
<td>
|
|
1096
|
+
<pre class="lines">
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
69
|
|
1100
|
+
70
|
|
1101
|
+
71</pre>
|
|
1102
|
+
</td>
|
|
1103
|
+
<td>
|
|
1104
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 69</span>
|
|
1105
|
+
|
|
1106
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_interactive'>interactive</span>
|
|
1107
|
+
<span class='ivar'>@interactive</span>
|
|
1108
|
+
<span class='kw'>end</span></pre>
|
|
1109
|
+
</td>
|
|
1110
|
+
</tr>
|
|
1111
|
+
</table>
|
|
1112
|
+
</div>
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
<span id=""></span>
|
|
1116
|
+
<div class="method_details ">
|
|
1117
|
+
<h3 class="signature " id="port_number-instance_method">
|
|
1118
|
+
|
|
1119
|
+
- (<tt>Object</tt>) <strong>port_number</strong> <span class="extras">(readonly)</span>
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
</h3><div class="docstring">
|
|
1126
|
+
<div class="discussion">
|
|
1127
|
+
|
|
1128
|
+
<p>Returns the value of attribute port_number</p>
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
</div>
|
|
1132
|
+
</div>
|
|
1133
|
+
<div class="tags">
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
</div><table class="source_code">
|
|
1137
|
+
<tr>
|
|
1138
|
+
<td>
|
|
1139
|
+
<pre class="lines">
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
104
|
|
1143
|
+
105
|
|
1144
|
+
106</pre>
|
|
1145
|
+
</td>
|
|
1146
|
+
<td>
|
|
1147
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 104</span>
|
|
1148
|
+
|
|
1149
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_port_number'>port_number</span>
|
|
1150
|
+
<span class='ivar'>@port_number</span>
|
|
1151
|
+
<span class='kw'>end</span></pre>
|
|
1152
|
+
</td>
|
|
1153
|
+
</tr>
|
|
1154
|
+
</table>
|
|
1155
|
+
</div>
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
<span id=""></span>
|
|
1159
|
+
<div class="method_details ">
|
|
1160
|
+
<h3 class="signature " id="port_width-instance_method">
|
|
1161
|
+
|
|
1162
|
+
- (<tt>Object</tt>) <strong>port_width</strong> <span class="extras">(readonly)</span>
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
</h3><div class="docstring">
|
|
1169
|
+
<div class="discussion">
|
|
1170
|
+
|
|
1171
|
+
<p>Returns the value of attribute port_width</p>
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
</div>
|
|
1175
|
+
</div>
|
|
1176
|
+
<div class="tags">
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
</div><table class="source_code">
|
|
1180
|
+
<tr>
|
|
1181
|
+
<td>
|
|
1182
|
+
<pre class="lines">
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
105
|
|
1186
|
+
106
|
|
1187
|
+
107</pre>
|
|
1188
|
+
</td>
|
|
1189
|
+
<td>
|
|
1190
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 105</span>
|
|
1191
|
+
|
|
1192
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_port_width'>port_width</span>
|
|
1193
|
+
<span class='ivar'>@port_width</span>
|
|
1194
|
+
<span class='kw'>end</span></pre>
|
|
1195
|
+
</td>
|
|
1196
|
+
</tr>
|
|
1197
|
+
</table>
|
|
1198
|
+
</div>
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
<span id=""></span>
|
|
1202
|
+
<div class="method_details ">
|
|
1203
|
+
<h3 class="signature " id="readline-instance_method">
|
|
1204
|
+
|
|
1205
|
+
- (<tt>Object</tt>) <strong>readline</strong> <span class="extras">(readonly)</span>
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
</h3><div class="docstring">
|
|
1212
|
+
<div class="discussion">
|
|
1213
|
+
|
|
1214
|
+
<p>Returns the value of attribute readline</p>
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
</div>
|
|
1218
|
+
</div>
|
|
1219
|
+
<div class="tags">
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
</div><table class="source_code">
|
|
1223
|
+
<tr>
|
|
1224
|
+
<td>
|
|
1225
|
+
<pre class="lines">
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
70
|
|
1229
|
+
71
|
|
1230
|
+
72</pre>
|
|
1231
|
+
</td>
|
|
1232
|
+
<td>
|
|
1233
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 70</span>
|
|
1234
|
+
|
|
1235
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_readline'>readline</span>
|
|
1236
|
+
<span class='ivar'>@readline</span>
|
|
1237
|
+
<span class='kw'>end</span></pre>
|
|
1238
|
+
</td>
|
|
1239
|
+
</tr>
|
|
1240
|
+
</table>
|
|
1241
|
+
</div>
|
|
1242
|
+
|
|
1243
|
+
</div>
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
<div id="instance_method_details" class="method_details_list">
|
|
1247
|
+
<h2>Instance Method Details</h2>
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
<div class="method_details first">
|
|
1251
|
+
<h3 class="signature first" id="assign-instance_method">
|
|
1252
|
+
|
|
1253
|
+
- (<tt>Object</tt>) <strong>assign</strong>(name, value)
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
</h3><div class="docstring">
|
|
1260
|
+
<div class="discussion">
|
|
1261
|
+
|
|
1262
|
+
<p>Data is copied from Ruby to R using the assign method or a short-hand
|
|
1263
|
+
equivalent. For example:</p>
|
|
1264
|
+
|
|
1265
|
+
<pre class="code ruby"><code class="ruby">>> names = ["Lisa","Teasha","Aaron","Thomas"]
|
|
1266
|
+
>> R.assign "people", names
|
|
1267
|
+
>> R.eval "sort(people)"</code></pre>
|
|
1268
|
+
|
|
1269
|
+
<p>produces the following :</p>
|
|
1270
|
+
|
|
1271
|
+
<pre class="code ruby"><code class="ruby">[1] "Aaron" "Lisa" "Teasha" "Thomas"</code></pre>
|
|
1272
|
+
|
|
1273
|
+
<p>The short-hand equivalent to the assign method is simply:</p>
|
|
1274
|
+
|
|
1275
|
+
<pre class="code ruby"><code class="ruby">>> R.people = names</code></pre>
|
|
1276
|
+
|
|
1277
|
+
<p>Some care is needed when using the short-hand of the assign method since
|
|
1278
|
+
the label (i.e., people in this case) must be a valid method name in Ruby.
|
|
1279
|
+
For example, R.copy.of.names = names will not work, but R.copy_of_names =
|
|
1280
|
+
names is permissible.</p>
|
|
1281
|
+
|
|
1282
|
+
<p>The assign method supports Ruby variables of type Fixnum (i.e., integer),
|
|
1283
|
+
Bignum (i.e., integer), Float (i.e., double), String, and arrays of one of
|
|
1284
|
+
those three fundamental types. Note that Fixnum or Bignum values that
|
|
1285
|
+
exceed the capacity of R’s integers are silently converted to doubles.
|
|
1286
|
+
Data in other formats must be coerced when copying to R.</p>
|
|
1287
|
+
|
|
1288
|
+
<p><strong>Parameters that can be passed to the assign method:</strong></p>
|
|
1289
|
+
<ul><li>
|
|
1290
|
+
<p>name: The name of the variable desired in R.</p>
|
|
1291
|
+
</li><li>
|
|
1292
|
+
<p>value: The value the R variable should have. The assign method supports
|
|
1293
|
+
Ruby variables of type Fixnum (i.e., integer), Bignum (i.e., integer),
|
|
1294
|
+
Float (i.e., double), String, and arrays of one of those three fundamental
|
|
1295
|
+
types. Note that Fixnum or Bignum values that exceed the capacity of R’s
|
|
1296
|
+
integers are silently converted to doubles. Data in other formats must be
|
|
1297
|
+
coerced when copying to R.</p>
|
|
1298
|
+
</li></ul>
|
|
1299
|
+
|
|
1300
|
+
<p>The assign method is an alternative to the simplified method, with some
|
|
1301
|
+
additional flexibility. When using the simplified method, the parameters of
|
|
1302
|
+
name and value are automatically used, in other words:</p>
|
|
1303
|
+
|
|
1304
|
+
<pre class="code ruby"><code class="ruby">>> R.test = 144</code></pre>
|
|
1305
|
+
|
|
1306
|
+
<p>is the same as:</p>
|
|
1307
|
+
|
|
1308
|
+
<pre class="code ruby"><code class="ruby">>> R.assign("test",144)</code></pre>
|
|
1309
|
+
|
|
1310
|
+
<p>Of course it would be confusing to use the shorthand notation to assign a
|
|
1311
|
+
variable named eval, echo, or any other already defined function. RinRuby
|
|
1312
|
+
would assume you were calling the function, rather than trying to assign a
|
|
1313
|
+
variable.</p>
|
|
1314
|
+
|
|
1315
|
+
<p>When assigning an array containing differing types of variables, RinRuby
|
|
1316
|
+
will follow R’s conversion conventions. An array that contains any Strings
|
|
1317
|
+
will result in a character vector in R. If the array does not contain any
|
|
1318
|
+
Strings, but it does contain a Float or a large integer (in absolute
|
|
1319
|
+
value), then the result will be a numeric vector of Doubles in R. If there
|
|
1320
|
+
are only integers that are suffciently small (in absolute value), then the
|
|
1321
|
+
result will be a numeric vector of integers in R.</p>
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
</div>
|
|
1325
|
+
</div>
|
|
1326
|
+
<div class="tags">
|
|
1327
|
+
|
|
1328
|
+
<p class="tag_title">Raises:</p>
|
|
1329
|
+
<ul class="raise">
|
|
1330
|
+
|
|
1331
|
+
<li>
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
<span class='type'>(<tt><span class='object_link'><a href="#EngineClosed-constant" title="RinRuby::EngineClosed (constant)">EngineClosed</a></span></tt>)</span>
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
</li>
|
|
1339
|
+
|
|
1340
|
+
</ul>
|
|
1341
|
+
|
|
1342
|
+
</div><table class="source_code">
|
|
1343
|
+
<tr>
|
|
1344
|
+
<td>
|
|
1345
|
+
<pre class="lines">
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
404
|
|
1349
|
+
405
|
|
1350
|
+
406
|
|
1351
|
+
407
|
|
1352
|
+
408
|
|
1353
|
+
409
|
|
1354
|
+
410
|
|
1355
|
+
411</pre>
|
|
1356
|
+
</td>
|
|
1357
|
+
<td>
|
|
1358
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 404</span>
|
|
1359
|
+
|
|
1360
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_assign'>assign</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
1361
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>EngineClosed</span> <span class='kw'>if</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
|
1362
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_assignable?'>assignable?</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
|
1363
|
+
<span class='id identifier rubyid_assign_engine'>assign_engine</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
1364
|
+
<span class='kw'>else</span>
|
|
1365
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ParseError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Parse error</span><span class='tstring_end'>"</span></span>
|
|
1366
|
+
<span class='kw'>end</span>
|
|
1367
|
+
<span class='kw'>end</span></pre>
|
|
1368
|
+
</td>
|
|
1369
|
+
</tr>
|
|
1370
|
+
</table>
|
|
1371
|
+
</div>
|
|
1372
|
+
|
|
1373
|
+
<div class="method_details ">
|
|
1374
|
+
<h3 class="signature " id="complete?-instance_method">
|
|
1375
|
+
|
|
1376
|
+
- (<tt>Boolean</tt>) <strong>complete?</strong>(string)
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
</h3><div class="docstring">
|
|
1383
|
+
<div class="discussion">
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
</div>
|
|
1387
|
+
</div>
|
|
1388
|
+
<div class="tags">
|
|
1389
|
+
|
|
1390
|
+
<p class="tag_title">Returns:</p>
|
|
1391
|
+
<ul class="return">
|
|
1392
|
+
|
|
1393
|
+
<li>
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
</li>
|
|
1401
|
+
|
|
1402
|
+
</ul>
|
|
1403
|
+
|
|
1404
|
+
</div><table class="source_code">
|
|
1405
|
+
<tr>
|
|
1406
|
+
<td>
|
|
1407
|
+
<pre class="lines">
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+
727
|
|
1411
|
+
728
|
|
1412
|
+
729
|
|
1413
|
+
730
|
|
1414
|
+
731
|
|
1415
|
+
732
|
|
1416
|
+
733
|
|
1417
|
+
734
|
|
1418
|
+
735
|
|
1419
|
+
736
|
|
1420
|
+
737
|
|
1421
|
+
738
|
|
1422
|
+
739
|
|
1423
|
+
740
|
|
1424
|
+
741
|
|
1425
|
+
742
|
|
1426
|
+
743
|
|
1427
|
+
744
|
|
1428
|
+
745</pre>
|
|
1429
|
+
</td>
|
|
1430
|
+
<td>
|
|
1431
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 727</span>
|
|
1432
|
+
|
|
1433
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_complete?'>complete?</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
|
|
1434
|
+
<span class='id identifier rubyid_assign_engine'>assign_engine</span><span class='lparen'>(</span><span class='const'>RinRuby_Parse_String</span><span class='comma'>,</span> <span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
|
|
1435
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>rinruby_parseable(</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Parse_String</span><span class='rbrace'>}</span><span class='tstring_content'>)</span><span class='tstring_end'>"</span></span>
|
|
1436
|
+
<span class='id identifier rubyid_buffer'>buffer</span><span class='op'>=</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span>
|
|
1437
|
+
<span class='ivar'>@socket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='int'>4</span><span class='comma'>,</span><span class='id identifier rubyid_buffer'>buffer</span><span class='rparen'>)</span>
|
|
1438
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>rm(</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Parse_String</span><span class='rbrace'>}</span><span class='tstring_content'>)</span><span class='tstring_end'>"</span></span>
|
|
1439
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_to_signed_int'>to_signed_int</span><span class='lparen'>(</span><span class='id identifier rubyid_buffer'>buffer</span><span class='period'>.</span><span class='id identifier rubyid_unpack'>unpack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>N</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='rparen'>)</span>
|
|
1440
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span><span class='op'>==</span><span class='op'>-</span><span class='int'>1</span> <span class='op'>?</span> <span class='kw'>false</span> <span class='op'>:</span> <span class='kw'>true</span>
|
|
1441
|
+
|
|
1442
|
+
<span class='embdoc_beg'>=begin
|
|
1443
|
+
</span><span class='embdoc'>
|
|
1444
|
+
</span><span class='embdoc'> result = pull_engine("unlist(lapply(c('.*','^Error in parse.*','^Error in parse.*unexpected end of input.*'),
|
|
1445
|
+
</span><span class='embdoc'> grep,try({parse(text=#{RinRuby_Parse_String}); 1}, silent=TRUE)))")
|
|
1446
|
+
</span><span class='embdoc'>
|
|
1447
|
+
</span><span class='embdoc'> return true if result.length == 1
|
|
1448
|
+
</span><span class='embdoc'> return false if result.length == 3
|
|
1449
|
+
</span><span class='embdoc'> raise ParseError, "Parse error"
|
|
1450
|
+
</span><span class='embdoc_end'>=end
|
|
1451
|
+
</span><span class='kw'>end</span></pre>
|
|
1452
|
+
</td>
|
|
1453
|
+
</tr>
|
|
1454
|
+
</table>
|
|
1455
|
+
</div>
|
|
1456
|
+
|
|
1457
|
+
<div class="method_details ">
|
|
1458
|
+
<h3 class="signature " id="echo-instance_method">
|
|
1459
|
+
|
|
1460
|
+
- (<tt>Object</tt>) <strong>echo</strong>(enable = nil, stderr = nil)
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
</h3><div class="docstring">
|
|
1467
|
+
<div class="discussion">
|
|
1468
|
+
|
|
1469
|
+
<p>The echo method controls whether the eval method displays output from R
|
|
1470
|
+
and, if echo is enabled, whether messages, warnings, and errors from stderr
|
|
1471
|
+
are also displayed.</p>
|
|
1472
|
+
|
|
1473
|
+
<p><strong>Parameters that can be passed to the eval method</strong></p>
|
|
1474
|
+
<ul><li>
|
|
1475
|
+
<p>enable: Setting enable to false will turn all output off until the echo
|
|
1476
|
+
command is used again with enable equal to true. The default is nil, which
|
|
1477
|
+
will return the current setting.</p>
|
|
1478
|
+
</li><li>
|
|
1479
|
+
<p>stderr: Setting stderr to true will force messages, warnings, and errors
|
|
1480
|
+
from R to be routed through stdout. Using stderr redirection is typically
|
|
1481
|
+
not needed for the C implementation of Ruby and is thus not not enabled by
|
|
1482
|
+
default for this implementation. It is typically necessary for jRuby and
|
|
1483
|
+
is enabled by default in this case. This redirection works well in
|
|
1484
|
+
practice but it can lead to interleaving output which may confuse RinRuby.
|
|
1485
|
+
In such cases, stderr redirection should not be used. Echoing must be
|
|
1486
|
+
enabled when using stderr redirection.</p>
|
|
1487
|
+
</li></ul>
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
</div>
|
|
1491
|
+
</div>
|
|
1492
|
+
<div class="tags">
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
</div><table class="source_code">
|
|
1496
|
+
<tr>
|
|
1497
|
+
<td>
|
|
1498
|
+
<pre class="lines">
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
487
|
|
1502
|
+
488
|
|
1503
|
+
489
|
|
1504
|
+
490
|
|
1505
|
+
491
|
|
1506
|
+
492
|
|
1507
|
+
493
|
|
1508
|
+
494
|
|
1509
|
+
495
|
|
1510
|
+
496
|
|
1511
|
+
497
|
|
1512
|
+
498
|
|
1513
|
+
499
|
|
1514
|
+
500
|
|
1515
|
+
501
|
|
1516
|
+
502
|
|
1517
|
+
503
|
|
1518
|
+
504</pre>
|
|
1519
|
+
</td>
|
|
1520
|
+
<td>
|
|
1521
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 487</span>
|
|
1522
|
+
|
|
1523
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='id identifier rubyid_enable'>enable</span><span class='op'>=</span><span class='kw'>nil</span><span class='comma'>,</span><span class='id identifier rubyid_stderr'>stderr</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span>
|
|
1524
|
+
<span class='kw'>if</span> <span class='lparen'>(</span> <span class='id identifier rubyid_enable'>enable</span> <span class='op'>==</span> <span class='kw'>false</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_stderr'>stderr</span> <span class='op'>==</span> <span class='kw'>true</span> <span class='rparen'>)</span>
|
|
1525
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>You can only redirect stderr if you are echoing is enabled.</span><span class='tstring_end'>"</span></span>
|
|
1526
|
+
<span class='kw'>end</span>
|
|
1527
|
+
<span class='kw'>if</span> <span class='lparen'>(</span> <span class='id identifier rubyid_enable'>enable</span> <span class='op'>!=</span> <span class='kw'>nil</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_enable'>enable</span> <span class='op'>!=</span> <span class='ivar'>@echo_enabled</span> <span class='rparen'>)</span>
|
|
1528
|
+
<span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='comma'>,</span><span class='kw'>false</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span> <span class='id identifier rubyid_enable'>enable</span>
|
|
1529
|
+
<span class='ivar'>@echo_enabled</span> <span class='op'>=</span> <span class='op'>!</span> <span class='ivar'>@echo_enabled</span>
|
|
1530
|
+
<span class='kw'>end</span>
|
|
1531
|
+
<span class='kw'>if</span> <span class='ivar'>@echo_enabled</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_stderr'>stderr</span> <span class='op'>!=</span> <span class='kw'>nil</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_stderr'>stderr</span> <span class='op'>!=</span> <span class='ivar'>@echo_stderr</span> <span class='rparen'>)</span>
|
|
1532
|
+
<span class='ivar'>@echo_stderr</span> <span class='op'>=</span> <span class='op'>!</span> <span class='ivar'>@echo_stderr</span>
|
|
1533
|
+
<span class='kw'>if</span> <span class='ivar'>@echo_stderr</span>
|
|
1534
|
+
<span class='id identifier rubyid_eval'>eval</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>sink(stdout(),type='message')</span><span class='tstring_end'>"</span></span>
|
|
1535
|
+
<span class='kw'>else</span>
|
|
1536
|
+
<span class='id identifier rubyid_eval'>eval</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>sink(type='message')</span><span class='tstring_end'>"</span></span>
|
|
1537
|
+
<span class='kw'>end</span>
|
|
1538
|
+
<span class='kw'>end</span>
|
|
1539
|
+
<span class='lbracket'>[</span> <span class='ivar'>@echo_enabled</span><span class='comma'>,</span> <span class='ivar'>@echo_stderr</span> <span class='rbracket'>]</span>
|
|
1540
|
+
<span class='kw'>end</span></pre>
|
|
1541
|
+
</td>
|
|
1542
|
+
</tr>
|
|
1543
|
+
</table>
|
|
1544
|
+
</div>
|
|
1545
|
+
|
|
1546
|
+
<div class="method_details ">
|
|
1547
|
+
<h3 class="signature " id="eval-instance_method">
|
|
1548
|
+
|
|
1549
|
+
- (<tt>Object</tt>) <strong>eval</strong>(string, echo_override = nil)
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
</h3><div class="docstring">
|
|
1556
|
+
<div class="discussion">
|
|
1557
|
+
|
|
1558
|
+
<p>The eval instance method passes the R commands contained in the supplied
|
|
1559
|
+
string and displays any resulting plots or prints the output. For example:</p>
|
|
1560
|
+
|
|
1561
|
+
<pre class="code ruby"><code class="ruby">>> sample_size = 10
|
|
1562
|
+
>> R.eval "x <- rnorm(#{sample_size})"
|
|
1563
|
+
>> R.eval "summary(x)"
|
|
1564
|
+
>> R.eval "sd(x)"</code></pre>
|
|
1565
|
+
|
|
1566
|
+
<p>produces the following:</p>
|
|
1567
|
+
|
|
1568
|
+
<pre class="code ruby"><code class="ruby"> Min. 1st Qu. Median Mean 3rd Qu. Max.
|
|
1569
|
+
-1.88900 -0.84930 -0.45220 -0.49290 -0.06069 0.78160
|
|
1570
|
+
[1] 0.7327981</code></pre>
|
|
1571
|
+
|
|
1572
|
+
<p>This example used a string substitution to make the argument to first eval
|
|
1573
|
+
method equivalent to x <- rnorm(10). This example used three invocations
|
|
1574
|
+
of the eval method, but a single invoke is possible using a here document:</p>
|
|
1575
|
+
|
|
1576
|
+
<pre class="code ruby"><code class="ruby">>> R.eval <<EOF
|
|
1577
|
+
x <- rnorm(#{sample_size})
|
|
1578
|
+
summary(x)
|
|
1579
|
+
sd(x)
|
|
1580
|
+
EOF</code></pre>
|
|
1581
|
+
|
|
1582
|
+
<p><strong>Parameters that can be passed to the eval method</strong></p>
|
|
1583
|
+
<ul><li>
|
|
1584
|
+
<p>string: The string parameter is the code which is to be passed to R, for
|
|
1585
|
+
example, string = "hist(gamma(1000,5,3))". The string can also span several
|
|
1586
|
+
lines of code by use of a here document, as shown:</p>
|
|
1587
|
+
|
|
1588
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>R</span><span class='period'>.</span><span class='id identifier rubyid_eval'>eval</span> <span class='heredoc_beg'><<EOF</span>
|
|
1589
|
+
<span class='tstring_content'> x<-rgamma(1000,5,3)
|
|
1590
|
+
hist(x)
|
|
1591
|
+
</span><span class='heredoc_end'>EOF</span></code></pre>
|
|
1592
|
+
</li><li>
|
|
1593
|
+
<p>echo_override: This argument allows one to set the echo behavior for this
|
|
1594
|
+
call only. The default for echo_override is nil, which does not override
|
|
1595
|
+
the current echo behavior.</p>
|
|
1596
|
+
</li></ul>
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
</div>
|
|
1600
|
+
</div>
|
|
1601
|
+
<div class="tags">
|
|
1602
|
+
|
|
1603
|
+
<p class="tag_title">Raises:</p>
|
|
1604
|
+
<ul class="raise">
|
|
1605
|
+
|
|
1606
|
+
<li>
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
<span class='type'>(<tt><span class='object_link'><a href="#EngineClosed-constant" title="RinRuby::EngineClosed (constant)">EngineClosed</a></span></tt>)</span>
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
</li>
|
|
1614
|
+
|
|
1615
|
+
</ul>
|
|
1616
|
+
|
|
1617
|
+
</div><table class="source_code">
|
|
1618
|
+
<tr>
|
|
1619
|
+
<td>
|
|
1620
|
+
<pre class="lines">
|
|
1621
|
+
|
|
1622
|
+
|
|
1623
|
+
242
|
|
1624
|
+
243
|
|
1625
|
+
244
|
|
1626
|
+
245
|
|
1627
|
+
246
|
|
1628
|
+
247
|
|
1629
|
+
248
|
|
1630
|
+
249
|
|
1631
|
+
250
|
|
1632
|
+
251
|
|
1633
|
+
252
|
|
1634
|
+
253
|
|
1635
|
+
254
|
|
1636
|
+
255
|
|
1637
|
+
256
|
|
1638
|
+
257
|
|
1639
|
+
258
|
|
1640
|
+
259
|
|
1641
|
+
260
|
|
1642
|
+
261
|
|
1643
|
+
262
|
|
1644
|
+
263
|
|
1645
|
+
264
|
|
1646
|
+
265
|
|
1647
|
+
266
|
|
1648
|
+
267
|
|
1649
|
+
268
|
|
1650
|
+
269
|
|
1651
|
+
270
|
|
1652
|
+
271
|
|
1653
|
+
272
|
|
1654
|
+
273
|
|
1655
|
+
274
|
|
1656
|
+
275
|
|
1657
|
+
276
|
|
1658
|
+
277
|
|
1659
|
+
278
|
|
1660
|
+
279
|
|
1661
|
+
280
|
|
1662
|
+
281
|
|
1663
|
+
282
|
|
1664
|
+
283
|
|
1665
|
+
284
|
|
1666
|
+
285
|
|
1667
|
+
286
|
|
1668
|
+
287
|
|
1669
|
+
288
|
|
1670
|
+
289
|
|
1671
|
+
290
|
|
1672
|
+
291
|
|
1673
|
+
292</pre>
|
|
1674
|
+
</td>
|
|
1675
|
+
<td>
|
|
1676
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 242</span>
|
|
1677
|
+
|
|
1678
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='comma'>,</span> <span class='id identifier rubyid_echo_override'>echo_override</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span>
|
|
1679
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>EngineClosed</span> <span class='kw'>if</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
|
1680
|
+
<span class='id identifier rubyid_echo_enabled'>echo_enabled</span> <span class='op'>=</span> <span class='lparen'>(</span> <span class='id identifier rubyid_echo_override'>echo_override</span> <span class='op'>!=</span> <span class='kw'>nil</span> <span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_echo_override'>echo_override</span> <span class='op'>:</span> <span class='ivar'>@echo_enabled</span>
|
|
1681
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_complete?'>complete?</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
|
|
1682
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_string'>string</span>
|
|
1683
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>warning('</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Stderr_Flag</span><span class='rbrace'>}</span><span class='tstring_content'>',immediate.=TRUE)</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='ivar'>@echo_stderr</span>
|
|
1684
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>print('</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Eval_Flag</span><span class='rbrace'>}</span><span class='tstring_content'>')</span><span class='tstring_end'>"</span></span>
|
|
1685
|
+
<span class='kw'>else</span>
|
|
1686
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ParseError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Parse error on eval:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_string'>string</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
|
1687
|
+
<span class='kw'>end</span>
|
|
1688
|
+
<span class='const'>Signal</span><span class='period'>.</span><span class='id identifier rubyid_trap'>trap</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>INT</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
|
1689
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'></span><span class='tstring_end'>'</span></span>
|
|
1690
|
+
<span class='ivar'>@reader</span><span class='period'>.</span><span class='id identifier rubyid_gets'>gets</span> <span class='kw'>if</span> <span class='ivar'>@platform</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>java</span><span class='regexp_end'>/</span></span>
|
|
1691
|
+
<span class='const'>Signal</span><span class='period'>.</span><span class='id identifier rubyid_trap'>trap</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>INT</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
|
1692
|
+
<span class='kw'>end</span>
|
|
1693
|
+
<span class='kw'>return</span> <span class='kw'>true</span>
|
|
1694
|
+
<span class='kw'>end</span>
|
|
1695
|
+
<span class='id identifier rubyid_found_eval_flag'>found_eval_flag</span> <span class='op'>=</span> <span class='kw'>false</span>
|
|
1696
|
+
<span class='id identifier rubyid_found_stderr_flag'>found_stderr_flag</span> <span class='op'>=</span> <span class='kw'>false</span>
|
|
1697
|
+
<span class='kw'>while</span> <span class='kw'>true</span>
|
|
1698
|
+
<span class='id identifier rubyid_echo_eligible'>echo_eligible</span> <span class='op'>=</span> <span class='kw'>true</span>
|
|
1699
|
+
<span class='kw'>begin</span>
|
|
1700
|
+
<span class='id identifier rubyid_line'>line</span> <span class='op'>=</span> <span class='ivar'>@reader</span><span class='period'>.</span><span class='id identifier rubyid_gets'>gets</span>
|
|
1701
|
+
<span class='kw'>rescue</span>
|
|
1702
|
+
<span class='kw'>return</span> <span class='kw'>false</span>
|
|
1703
|
+
<span class='kw'>end</span>
|
|
1704
|
+
<span class='kw'>if</span> <span class='op'>!</span> <span class='id identifier rubyid_line'>line</span>
|
|
1705
|
+
<span class='kw'>return</span> <span class='kw'>false</span>
|
|
1706
|
+
<span class='kw'>end</span>
|
|
1707
|
+
<span class='kw'>while</span> <span class='id identifier rubyid_line'>line</span><span class='period'>.</span><span class='id identifier rubyid_chomp!'>chomp!</span>
|
|
1708
|
+
<span class='kw'>end</span>
|
|
1709
|
+
<span class='id identifier rubyid_line'>line</span> <span class='op'>=</span> <span class='id identifier rubyid_line'>line</span><span class='lbracket'>[</span><span class='int'>8</span><span class='op'>..</span><span class='op'>-</span><span class='int'>1</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_line'>line</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='int'>27</span> <span class='comment'># Delete escape sequence
|
|
1710
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_line'>line</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[1] \"</span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Eval_Flag</span><span class='rbrace'>}</span><span class='tstring_content'>\"</span><span class='tstring_end'>"</span></span>
|
|
1711
|
+
<span class='id identifier rubyid_found_eval_flag'>found_eval_flag</span> <span class='op'>=</span> <span class='kw'>true</span>
|
|
1712
|
+
<span class='id identifier rubyid_echo_eligible'>echo_eligible</span> <span class='op'>=</span> <span class='kw'>false</span>
|
|
1713
|
+
<span class='kw'>end</span>
|
|
1714
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_line'>line</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Warning: </span><span class='embexpr_beg'>#{</span><span class='const'>RinRuby_Stderr_Flag</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
|
1715
|
+
<span class='id identifier rubyid_found_stderr_flag'>found_stderr_flag</span> <span class='op'>=</span> <span class='kw'>true</span>
|
|
1716
|
+
<span class='id identifier rubyid_echo_eligible'>echo_eligible</span> <span class='op'>=</span> <span class='kw'>false</span>
|
|
1717
|
+
<span class='kw'>end</span>
|
|
1718
|
+
<span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_found_eval_flag'>found_eval_flag</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_found_stderr_flag'>found_stderr_flag</span> <span class='op'>==</span> <span class='ivar'>@echo_stderr</span> <span class='rparen'>)</span>
|
|
1719
|
+
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>if</span> <span class='id identifier rubyid_line'>line</span> <span class='op'>==</span> <span class='const'>RinRuby_Exit_Flag</span>
|
|
1720
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_echo_enabled'>echo_enabled</span> <span class='op'>&&</span> <span class='id identifier rubyid_echo_eligible'>echo_eligible</span>
|
|
1721
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_line'>line</span>
|
|
1722
|
+
<span class='gvar'>$stdout</span><span class='period'>.</span><span class='id identifier rubyid_flush'>flush</span> <span class='kw'>if</span> <span class='ivar'>@platform</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>windows</span><span class='regexp_end'>/</span></span>
|
|
1723
|
+
<span class='kw'>end</span>
|
|
1724
|
+
<span class='kw'>end</span>
|
|
1725
|
+
<span class='const'>Signal</span><span class='period'>.</span><span class='id identifier rubyid_trap'>trap</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>INT</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
|
1726
|
+
<span class='kw'>end</span>
|
|
1727
|
+
<span class='kw'>true</span>
|
|
1728
|
+
<span class='kw'>end</span></pre>
|
|
1729
|
+
</td>
|
|
1730
|
+
</tr>
|
|
1731
|
+
</table>
|
|
1732
|
+
</div>
|
|
1733
|
+
|
|
1734
|
+
<div class="method_details ">
|
|
1735
|
+
<h3 class="signature " id="prompt-instance_method">
|
|
1736
|
+
|
|
1737
|
+
- (<tt>Object</tt>) <strong>prompt</strong>(regular_prompt = "> ", continue_prompt = "+ ")
|
|
1738
|
+
|
|
1739
|
+
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
</h3><div class="docstring">
|
|
1744
|
+
<div class="discussion">
|
|
1745
|
+
|
|
1746
|
+
<p>When sending code to Ruby using an interactive prompt, this method will
|
|
1747
|
+
change the prompt to an R prompt. From the R prompt commands can be sent to
|
|
1748
|
+
R exactly as if the R program was actually running. When the user is ready
|
|
1749
|
+
to return to Ruby, then the command exit() will return the prompt to Ruby.
|
|
1750
|
+
This is the ideal situation for the explorative programmer who needs to run
|
|
1751
|
+
several lines of code in R, and see the results after each command. This is
|
|
1752
|
+
also an easy way to execute loops without the use of a here document. It
|
|
1753
|
+
should be noted that the prompt command does not work in a script, just
|
|
1754
|
+
Ruby's interactive irb.</p>
|
|
1755
|
+
|
|
1756
|
+
<p><strong>Parameters that can be passed to the prompt method:</strong></p>
|
|
1757
|
+
<ul><li>
|
|
1758
|
+
<p>regular_prompt: This defines the string used to denote the R prompt.</p>
|
|
1759
|
+
</li><li>
|
|
1760
|
+
<p>continue_prompt: This is the string used to denote R's prompt for an
|
|
1761
|
+
incomplete statement (such as a multiple for loop).</p>
|
|
1762
|
+
</li></ul>
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
</div>
|
|
1766
|
+
</div>
|
|
1767
|
+
<div class="tags">
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
</div><table class="source_code">
|
|
1771
|
+
<tr>
|
|
1772
|
+
<td>
|
|
1773
|
+
<pre class="lines">
|
|
1774
|
+
|
|
1775
|
+
|
|
1776
|
+
302
|
|
1777
|
+
303
|
|
1778
|
+
304
|
|
1779
|
+
305
|
|
1780
|
+
306
|
|
1781
|
+
307
|
|
1782
|
+
308
|
|
1783
|
+
309
|
|
1784
|
+
310
|
|
1785
|
+
311
|
|
1786
|
+
312
|
|
1787
|
+
313
|
|
1788
|
+
314
|
|
1789
|
+
315
|
|
1790
|
+
316
|
|
1791
|
+
317
|
|
1792
|
+
318
|
|
1793
|
+
319
|
|
1794
|
+
320
|
|
1795
|
+
321
|
|
1796
|
+
322
|
|
1797
|
+
323
|
|
1798
|
+
324
|
|
1799
|
+
325
|
|
1800
|
+
326
|
|
1801
|
+
327
|
|
1802
|
+
328
|
|
1803
|
+
329
|
|
1804
|
+
330
|
|
1805
|
+
331
|
|
1806
|
+
332
|
|
1807
|
+
333
|
|
1808
|
+
334
|
|
1809
|
+
335
|
|
1810
|
+
336</pre>
|
|
1811
|
+
</td>
|
|
1812
|
+
<td>
|
|
1813
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 302</span>
|
|
1814
|
+
|
|
1815
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_prompt'>prompt</span><span class='lparen'>(</span><span class='id identifier rubyid_regular_prompt'>regular_prompt</span><span class='op'>=</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_continue_prompt'>continue_prompt</span><span class='op'>=</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>+ </span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
1816
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>The 'prompt' method only available in 'interactive' mode</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='op'>!</span> <span class='ivar'>@interactive</span>
|
|
1817
|
+
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>if</span> <span class='op'>!</span> <span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0</span><span class='tstring_end'>"</span></span><span class='comma'>,</span><span class='kw'>false</span><span class='rparen'>)</span>
|
|
1818
|
+
<span class='id identifier rubyid_prompt'>prompt</span> <span class='op'>=</span> <span class='id identifier rubyid_regular_prompt'>regular_prompt</span>
|
|
1819
|
+
<span class='kw'>while</span> <span class='kw'>true</span>
|
|
1820
|
+
<span class='id identifier rubyid_cmds'>cmds</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
1821
|
+
<span class='kw'>while</span> <span class='kw'>true</span>
|
|
1822
|
+
<span class='kw'>if</span> <span class='ivar'>@readline</span> <span class='op'>&&</span> <span class='ivar'>@interactive</span>
|
|
1823
|
+
<span class='id identifier rubyid_cmd'>cmd</span> <span class='op'>=</span> <span class='const'>Readline</span><span class='period'>.</span><span class='id identifier rubyid_readline'>readline</span><span class='lparen'>(</span><span class='id identifier rubyid_prompt'>prompt</span><span class='comma'>,</span><span class='kw'>true</span><span class='rparen'>)</span>
|
|
1824
|
+
<span class='kw'>else</span>
|
|
1825
|
+
<span class='id identifier rubyid_print'>print</span> <span class='id identifier rubyid_prompt'>prompt</span>
|
|
1826
|
+
<span class='gvar'>$stdout</span><span class='period'>.</span><span class='id identifier rubyid_flush'>flush</span>
|
|
1827
|
+
<span class='id identifier rubyid_cmd'>cmd</span> <span class='op'>=</span> <span class='id identifier rubyid_gets'>gets</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
|
|
1828
|
+
<span class='kw'>end</span>
|
|
1829
|
+
<span class='id identifier rubyid_cmds'>cmds</span> <span class='op'><<</span> <span class='id identifier rubyid_cmd'>cmd</span>
|
|
1830
|
+
<span class='kw'>begin</span>
|
|
1831
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_complete?'>complete?</span><span class='lparen'>(</span><span class='id identifier rubyid_cmds'>cmds</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\n</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
1832
|
+
<span class='id identifier rubyid_prompt'>prompt</span> <span class='op'>=</span> <span class='id identifier rubyid_regular_prompt'>regular_prompt</span>
|
|
1833
|
+
<span class='kw'>break</span>
|
|
1834
|
+
<span class='kw'>else</span>
|
|
1835
|
+
<span class='id identifier rubyid_prompt'>prompt</span> <span class='op'>=</span> <span class='id identifier rubyid_continue_prompt'>continue_prompt</span>
|
|
1836
|
+
<span class='kw'>end</span>
|
|
1837
|
+
<span class='kw'>rescue</span>
|
|
1838
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Parse error</span><span class='tstring_end'>"</span></span>
|
|
1839
|
+
<span class='id identifier rubyid_prompt'>prompt</span> <span class='op'>=</span> <span class='id identifier rubyid_regular_prompt'>regular_prompt</span>
|
|
1840
|
+
<span class='id identifier rubyid_cmds'>cmds</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
1841
|
+
<span class='kw'>break</span>
|
|
1842
|
+
<span class='kw'>end</span>
|
|
1843
|
+
<span class='kw'>end</span>
|
|
1844
|
+
<span class='kw'>next</span> <span class='kw'>if</span> <span class='id identifier rubyid_cmds'>cmds</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>0</span>
|
|
1845
|
+
<span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_cmds'>cmds</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>&&</span> <span class='id identifier rubyid_cmds'>cmds</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>exit()</span><span class='tstring_end'>"</span></span>
|
|
1846
|
+
<span class='kw'>break</span> <span class='kw'>if</span> <span class='op'>!</span> <span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_cmds'>cmds</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\n</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span><span class='kw'>true</span><span class='rparen'>)</span>
|
|
1847
|
+
<span class='kw'>end</span>
|
|
1848
|
+
<span class='kw'>true</span>
|
|
1849
|
+
<span class='kw'>end</span></pre>
|
|
1850
|
+
</td>
|
|
1851
|
+
</tr>
|
|
1852
|
+
</table>
|
|
1853
|
+
</div>
|
|
1854
|
+
|
|
1855
|
+
<div class="method_details ">
|
|
1856
|
+
<h3 class="signature " id="pull-instance_method">
|
|
1857
|
+
|
|
1858
|
+
- (<tt>Object</tt>) <strong>pull</strong>(string, singletons = false)
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
</h3><div class="docstring">
|
|
1865
|
+
<div class="discussion">
|
|
1866
|
+
|
|
1867
|
+
<p>Data is copied from R to Ruby using the pull method or a short-hand
|
|
1868
|
+
equivalent. The R object x defined with an eval method can be copied to
|
|
1869
|
+
Ruby object copy_of_x as follows:</p>
|
|
1870
|
+
|
|
1871
|
+
<pre class="code ruby"><code class="ruby">>> R.eval "x <- rnorm(10)"
|
|
1872
|
+
>> copy_of_x = R.pull "x"
|
|
1873
|
+
>> puts copy_of_x</code></pre>
|
|
1874
|
+
|
|
1875
|
+
<p>which produces the following :</p>
|
|
1876
|
+
|
|
1877
|
+
<pre class="code ruby"><code class="ruby"><span class='op'>-</span><span class='float'>0.376404489256671</span>
|
|
1878
|
+
<span class='op'>-</span><span class='float'>1.0759798269397</span>
|
|
1879
|
+
<span class='op'>-</span><span class='float'>0.494240140140996</span>
|
|
1880
|
+
<span class='float'>0.131171385795721</span>
|
|
1881
|
+
<span class='op'>-</span><span class='float'>0.878328334369391</span>
|
|
1882
|
+
<span class='op'>-</span><span class='float'>0.762290423047929</span>
|
|
1883
|
+
<span class='op'>-</span><span class='float'>0.410227216105828</span>
|
|
1884
|
+
<span class='float'>0.0445512804225151</span>
|
|
1885
|
+
<span class='op'>-</span><span class='float'>1.88887454545995</span>
|
|
1886
|
+
<span class='float'>0.781602719849499</span></code></pre>
|
|
1887
|
+
|
|
1888
|
+
<p>RinRuby also supports a convenient short-hand notation when the argument to
|
|
1889
|
+
pull is simply a previously-defined R object (whose name conforms to Ruby's
|
|
1890
|
+
requirements for method names). For example:</p>
|
|
1891
|
+
|
|
1892
|
+
<pre class="code ruby"><code class="ruby">>> copy_of_x = R.x</code></pre>
|
|
1893
|
+
|
|
1894
|
+
<p>The explicit assign method, however, can take an arbitrary R statement. For
|
|
1895
|
+
example:</p>
|
|
1896
|
+
|
|
1897
|
+
<pre class="code ruby"><code class="ruby">>> summary_of_x = R.pull "as.numeric(summary(x))"
|
|
1898
|
+
>> puts summary_of_x</code></pre>
|
|
1899
|
+
|
|
1900
|
+
<p>produces the following:</p>
|
|
1901
|
+
|
|
1902
|
+
<pre class="code ruby"><code class="ruby"><span class='op'>-</span><span class='float'>1.889</span>
|
|
1903
|
+
<span class='op'>-</span><span class='float'>0.8493</span>
|
|
1904
|
+
<span class='op'>-</span><span class='float'>0.4522</span>
|
|
1905
|
+
<span class='op'>-</span><span class='float'>0.4929</span>
|
|
1906
|
+
<span class='op'>-</span><span class='float'>0.06069</span>
|
|
1907
|
+
<span class='float'>0.7816</span></code></pre>
|
|
1908
|
+
|
|
1909
|
+
<p>Notice the use above of the as.numeric function in R. This is necessary
|
|
1910
|
+
since the pull method only supports R vectors which are numeric (i.e.,
|
|
1911
|
+
integers or doubles) and character (i.e., strings). Data in other formats
|
|
1912
|
+
must be coerced when copying to Ruby.</p>
|
|
1913
|
+
|
|
1914
|
+
<p><strong>Parameters that can be passed to the pull method:</strong></p>
|
|
1915
|
+
<ul><li>
|
|
1916
|
+
<p>string: The name of the variable that should be pulled from R. The pull
|
|
1917
|
+
method only supports R vectors which are numeric (i.e., integers or
|
|
1918
|
+
doubles) or character (i.e., strings). The R value of NA is pulled as nil
|
|
1919
|
+
into Ruby. Data in other formats must be coerced when copying to Ruby.</p>
|
|
1920
|
+
</li><li>
|
|
1921
|
+
<p>singletons: R represents a single number as a vector of length one, but in
|
|
1922
|
+
Ruby it is often more convenient to use a number rather than an array of
|
|
1923
|
+
length one. Setting singleton=false will cause the pull method to shed the
|
|
1924
|
+
array, while singletons=true will return the number of string within an
|
|
1925
|
+
array. The default is false.</p>
|
|
1926
|
+
</li></ul>
|
|
1927
|
+
|
|
1928
|
+
<p>The pull method is an alternative to the simplified form where the
|
|
1929
|
+
parameters are automatically used. For example:</p>
|
|
1930
|
+
|
|
1931
|
+
<pre class="code ruby"><code class="ruby">>> puts R.test</code></pre>
|
|
1932
|
+
|
|
1933
|
+
<p>is the same as:</p>
|
|
1934
|
+
|
|
1935
|
+
<pre class="code ruby"><code class="ruby">>> puts R.pull("test")</code></pre>
|
|
1936
|
+
|
|
1937
|
+
|
|
1938
|
+
</div>
|
|
1939
|
+
</div>
|
|
1940
|
+
<div class="tags">
|
|
1941
|
+
|
|
1942
|
+
<p class="tag_title">Raises:</p>
|
|
1943
|
+
<ul class="raise">
|
|
1944
|
+
|
|
1945
|
+
<li>
|
|
1946
|
+
|
|
1947
|
+
|
|
1948
|
+
<span class='type'>(<tt><span class='object_link'><a href="#EngineClosed-constant" title="RinRuby::EngineClosed (constant)">EngineClosed</a></span></tt>)</span>
|
|
1949
|
+
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
</li>
|
|
1953
|
+
|
|
1954
|
+
</ul>
|
|
1955
|
+
|
|
1956
|
+
</div><table class="source_code">
|
|
1957
|
+
<tr>
|
|
1958
|
+
<td>
|
|
1959
|
+
<pre class="lines">
|
|
1960
|
+
|
|
1961
|
+
|
|
1962
|
+
466
|
|
1963
|
+
467
|
|
1964
|
+
468
|
|
1965
|
+
469
|
|
1966
|
+
470
|
|
1967
|
+
471
|
|
1968
|
+
472
|
|
1969
|
+
473
|
|
1970
|
+
474
|
|
1971
|
+
475
|
|
1972
|
+
476
|
|
1973
|
+
477</pre>
|
|
1974
|
+
</td>
|
|
1975
|
+
<td>
|
|
1976
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 466</span>
|
|
1977
|
+
|
|
1978
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_pull'>pull</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='comma'>,</span> <span class='id identifier rubyid_singletons'>singletons</span><span class='op'>=</span><span class='kw'>false</span><span class='rparen'>)</span>
|
|
1979
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>EngineClosed</span> <span class='kw'>if</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
|
1980
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_complete?'>complete?</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
|
|
1981
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_pull_engine'>pull_engine</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
|
|
1982
|
+
<span class='kw'>if</span> <span class='lparen'>(</span> <span class='op'>!</span> <span class='id identifier rubyid_singletons'>singletons</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='lparen'>(</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>!=</span> <span class='const'>String</span> <span class='rparen'>)</span>
|
|
1983
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
|
1984
|
+
<span class='kw'>end</span>
|
|
1985
|
+
<span class='id identifier rubyid_result'>result</span>
|
|
1986
|
+
<span class='kw'>else</span>
|
|
1987
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ParseError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Parse error</span><span class='tstring_end'>"</span></span>
|
|
1988
|
+
<span class='kw'>end</span>
|
|
1989
|
+
<span class='kw'>end</span></pre>
|
|
1990
|
+
</td>
|
|
1991
|
+
</tr>
|
|
1992
|
+
</table>
|
|
1993
|
+
</div>
|
|
1994
|
+
|
|
1995
|
+
<div class="method_details ">
|
|
1996
|
+
<h3 class="signature " id="quit-instance_method">
|
|
1997
|
+
|
|
1998
|
+
- (<tt>Object</tt>) <strong>quit</strong>
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
|
|
2004
|
+
</h3><div class="docstring">
|
|
2005
|
+
<div class="discussion">
|
|
2006
|
+
|
|
2007
|
+
<p>The quit method will properly close the bridge between Ruby and R, freeing
|
|
2008
|
+
up system resources. This method does not need to be run when a Ruby script
|
|
2009
|
+
ends.</p>
|
|
2010
|
+
|
|
2011
|
+
|
|
2012
|
+
</div>
|
|
2013
|
+
</div>
|
|
2014
|
+
<div class="tags">
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
</div><table class="source_code">
|
|
2018
|
+
<tr>
|
|
2019
|
+
<td>
|
|
2020
|
+
<pre class="lines">
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
191
|
|
2024
|
+
192
|
|
2025
|
+
193
|
|
2026
|
+
194
|
|
2027
|
+
195
|
|
2028
|
+
196
|
|
2029
|
+
197
|
|
2030
|
+
198
|
|
2031
|
+
199
|
|
2032
|
+
200
|
|
2033
|
+
201
|
|
2034
|
+
202
|
|
2035
|
+
203
|
|
2036
|
+
204
|
|
2037
|
+
205
|
|
2038
|
+
206
|
|
2039
|
+
207
|
|
2040
|
+
208</pre>
|
|
2041
|
+
</td>
|
|
2042
|
+
<td>
|
|
2043
|
+
<pre class="code"><span class="info file"># File 'lib/rinruby.rb', line 191</span>
|
|
2044
|
+
|
|
2045
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_quit'>quit</span>
|
|
2046
|
+
<span class='kw'>begin</span>
|
|
2047
|
+
<span class='ivar'>@writer</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>q(save='no')</span><span class='tstring_end'>"</span></span>
|
|
2048
|
+
<span class='comment'># TODO: Verify if read is needed
|
|
2049
|
+
</span> <span class='ivar'>@socket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
|
2050
|
+
<span class='comment'>#@socket.close
|
|
2051
|
+
</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
<span class='ivar'>@server_socket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
|
|
2055
|
+
<span class='comment'>#@reader.close
|
|
2056
|
+
</span> <span class='comment'>#@writer.close
|
|
2057
|
+
</span> <span class='kw'>true</span>
|
|
2058
|
+
<span class='kw'>ensure</span>
|
|
2059
|
+
<span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>unless</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
|
2060
|
+
<span class='ivar'>@server_socket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>unless</span> <span class='ivar'>@server_socket</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
|
2061
|
+
<span class='kw'>end</span>
|
|
2062
|
+
<span class='kw'>end</span></pre>
|
|
2063
|
+
</td>
|
|
2064
|
+
</tr>
|
|
2065
|
+
</table>
|
|
2066
|
+
</div>
|
|
2067
|
+
|
|
2068
|
+
</div>
|
|
2069
|
+
|
|
2070
|
+
</div>
|
|
2071
|
+
|
|
2072
|
+
<div id="footer">
|
|
2073
|
+
Generated on Tue Jul 14 18:12:22 2015 by
|
|
2074
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
2075
|
+
0.8.7.6 (ruby-1.9.3).
|
|
2076
|
+
</div>
|
|
2077
|
+
|
|
2078
|
+
</body>
|
|
2079
|
+
</html>
|