-
Notifications
You must be signed in to change notification settings - Fork 30
/
230_R_function.html
672 lines (625 loc) · 66.6 KB
/
230_R_function.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
863
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 23 Using R functions | Rcpp for everyone</title>
<meta name="description" content="Introducing how to use Rcpp" />
<meta name="generator" content="bookdown 0.18 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 23 Using R functions | Rcpp for everyone" />
<meta property="og:type" content="book" />
<meta property="og:description" content="Introducing how to use Rcpp" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 23 Using R functions | Rcpp for everyone" />
<meta name="twitter:description" content="Introducing how to use Rcpp" />
<meta name="author" content="Masaki E. Tsuda" />
<meta name="date" content="2020-10-20" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="220_dpqr_functions.html"/>
<link rel="next" href="240_na_nan_inf.html"/>
<script src="libs/header-attrs-2.1/header-attrs.js"></script>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-101879207-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-101879207-2');
</script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">Rcpp for everyone</a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Welcome</a></li>
<li class="chapter" data-level="1" data-path="010_Rcpp_merit.html"><a href="010_Rcpp_merit.html"><i class="fa fa-check"></i><b>1</b> Suitable situations to use Rcpp</a></li>
<li class="chapter" data-level="2" data-path="020_install.html"><a href="020_install.html"><i class="fa fa-check"></i><b>2</b> Installation</a>
<ul>
<li class="chapter" data-level="2.1" data-path="020_install.html"><a href="020_install.html#install-c-compiler"><i class="fa fa-check"></i><b>2.1</b> Install C compiler</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="020_install.html"><a href="020_install.html#windows"><i class="fa fa-check"></i><b>2.1.1</b> Windows</a></li>
<li class="chapter" data-level="2.1.2" data-path="020_install.html"><a href="020_install.html#mac"><i class="fa fa-check"></i><b>2.1.2</b> Mac</a></li>
<li class="chapter" data-level="2.1.3" data-path="020_install.html"><a href="020_install.html#linux"><i class="fa fa-check"></i><b>2.1.3</b> Linux</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="020_install.html"><a href="020_install.html#using-other-compilers-installed-by-yourself"><i class="fa fa-check"></i><b>2.2</b> Using other compilers installed by yourself</a></li>
<li class="chapter" data-level="2.3" data-path="020_install.html"><a href="020_install.html#install-rcpp"><i class="fa fa-check"></i><b>2.3</b> Install Rcpp</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="030_basic_usage.html"><a href="030_basic_usage.html"><i class="fa fa-check"></i><b>3</b> Basic usage</a>
<ul>
<li class="chapter" data-level="3.1" data-path="030_basic_usage.html"><a href="030_basic_usage.html#writing-your-rcpp-code"><i class="fa fa-check"></i><b>3.1</b> Writing your Rcpp code</a>
<ul>
<li class="chapter" data-level="3.1.1" data-path="030_basic_usage.html"><a href="030_basic_usage.html#format-for-defining-a-function-in-rcpp."><i class="fa fa-check"></i><b>3.1.1</b> Format for defining a function in Rcpp.</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="030_basic_usage.html"><a href="030_basic_usage.html#compiling-the-code"><i class="fa fa-check"></i><b>3.2</b> Compiling the code</a></li>
<li class="chapter" data-level="3.3" data-path="030_basic_usage.html"><a href="030_basic_usage.html#executing-the-function"><i class="fa fa-check"></i><b>3.3</b> Executing the function</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="040_function.html"><a href="040_function.html"><i class="fa fa-check"></i><b>4</b> Embedding Rcpp code in your R code</a>
<ul>
<li class="chapter" data-level="4.1" data-path="040_function.html"><a href="040_function.html#sourcecpp"><i class="fa fa-check"></i><b>4.1</b> sourceCpp()</a></li>
<li class="chapter" data-level="4.2" data-path="040_function.html"><a href="040_function.html#cppfunction"><i class="fa fa-check"></i><b>4.2</b> cppFunction()</a></li>
<li class="chapter" data-level="4.3" data-path="040_function.html"><a href="040_function.html#evalcpp"><i class="fa fa-check"></i><b>4.3</b> evalCpp()</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="050_c 11.html"><a href="050_c 11.html"><i class="fa fa-check"></i><b>5</b> C 11</a>
<ul>
<li class="chapter" data-level="5.1" data-path="050_c 11.html"><a href="050_c 11.html#enabling-c11"><i class="fa fa-check"></i><b>5.1</b> Enabling C 11</a></li>
<li class="chapter" data-level="5.2" data-path="050_c 11.html"><a href="050_c 11.html#recommended-c11-features"><i class="fa fa-check"></i><b>5.2</b> Recommended C 11 features</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="050_c 11.html"><a href="050_c 11.html#initializer-list"><i class="fa fa-check"></i><b>5.2.1</b> Initializer list</a></li>
<li class="chapter" data-level="5.2.2" data-path="050_c 11.html"><a href="050_c 11.html#auto"><i class="fa fa-check"></i><b>5.2.2</b> auto</a></li>
<li class="chapter" data-level="5.2.3" data-path="050_c 11.html"><a href="050_c 11.html#decltype"><i class="fa fa-check"></i><b>5.2.3</b> decltype</a></li>
<li class="chapter" data-level="5.2.4" data-path="050_c 11.html"><a href="050_c 11.html#range-based-for-loop"><i class="fa fa-check"></i><b>5.2.4</b> Range-based for-loop</a></li>
<li class="chapter" data-level="5.2.5" data-path="050_c 11.html"><a href="050_c 11.html#lambda-expression"><i class="fa fa-check"></i><b>5.2.5</b> Lambda expression</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="060_printing_massages.html"><a href="060_printing_massages.html"><i class="fa fa-check"></i><b>6</b> Printing messages</a>
<ul>
<li class="chapter" data-level="6.1" data-path="060_printing_massages.html"><a href="060_printing_massages.html#rcout-rcerr"><i class="fa fa-check"></i><b>6.1</b> Rcout, Rcerr</a></li>
<li class="chapter" data-level="6.2" data-path="060_printing_massages.html"><a href="060_printing_massages.html#rprintf-reprintf"><i class="fa fa-check"></i><b>6.2</b> Rprintf(), REprintf()</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="070_data_types.html"><a href="070_data_types.html"><i class="fa fa-check"></i><b>7</b> Data types</a>
<ul>
<li class="chapter" data-level="7.1" data-path="070_data_types.html"><a href="070_data_types.html#vector-and-matrix"><i class="fa fa-check"></i><b>7.1</b> Vector and Matrix</a></li>
<li class="chapter" data-level="7.2" data-path="070_data_types.html"><a href="070_data_types.html#data.frame-list-s3-s4"><i class="fa fa-check"></i><b>7.2</b> data.frame, list, S3, S4</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="080_vector.html"><a href="080_vector.html"><i class="fa fa-check"></i><b>8</b> Vector</a>
<ul>
<li class="chapter" data-level="8.1" data-path="080_vector.html"><a href="080_vector.html#creating-vector-object"><i class="fa fa-check"></i><b>8.1</b> Creating vector object</a></li>
<li class="chapter" data-level="8.2" data-path="080_vector.html"><a href="080_vector.html#accessing-vector-elements"><i class="fa fa-check"></i><b>8.2</b> Accessing vector elements</a></li>
<li class="chapter" data-level="8.3" data-path="080_vector.html"><a href="080_vector.html#member-functions-vector"><i class="fa fa-check"></i><b>8.3</b> Member functions</a>
<ul>
<li class="chapter" data-level="8.3.1" data-path="080_vector.html"><a href="080_vector.html#length-size"><i class="fa fa-check"></i><b>8.3.1</b> <code>length()</code>, <code>size()</code></a></li>
<li class="chapter" data-level="8.3.2" data-path="080_vector.html"><a href="080_vector.html#names"><i class="fa fa-check"></i><b>8.3.2</b> <code>names()</code></a></li>
<li class="chapter" data-level="8.3.3" data-path="080_vector.html"><a href="080_vector.html#offset-name-findname-name"><i class="fa fa-check"></i><b>8.3.3</b> <code>offset( name )</code>, <code>findName( name )</code></a></li>
<li class="chapter" data-level="8.3.4" data-path="080_vector.html"><a href="080_vector.html#offset-i"><i class="fa fa-check"></i><b>8.3.4</b> <code>offset( i )</code></a></li>
<li class="chapter" data-level="8.3.5" data-path="080_vector.html"><a href="080_vector.html#fill-x"><i class="fa fa-check"></i><b>8.3.5</b> <code>fill( x )</code></a></li>
<li class="chapter" data-level="8.3.6" data-path="080_vector.html"><a href="080_vector.html#sort"><i class="fa fa-check"></i><b>8.3.6</b> <code>sort()</code></a></li>
<li class="chapter" data-level="8.3.7" data-path="080_vector.html"><a href="080_vector.html#assign-first_it-last_it"><i class="fa fa-check"></i><b>8.3.7</b> <code>assign( first_it, last_it )</code></a></li>
<li class="chapter" data-level="8.3.8" data-path="080_vector.html"><a href="080_vector.html#push_back-x"><i class="fa fa-check"></i><b>8.3.8</b> <code>push_back( x )</code></a></li>
<li class="chapter" data-level="8.3.9" data-path="080_vector.html"><a href="080_vector.html#push_back-x-name"><i class="fa fa-check"></i><b>8.3.9</b> <code>push_back( x, name )</code></a></li>
<li class="chapter" data-level="8.3.10" data-path="080_vector.html"><a href="080_vector.html#push_front-x"><i class="fa fa-check"></i><b>8.3.10</b> <code>push_front( x )</code></a></li>
<li class="chapter" data-level="8.3.11" data-path="080_vector.html"><a href="080_vector.html#push_front-x-name"><i class="fa fa-check"></i><b>8.3.11</b> <code>push_front( x, name )</code></a></li>
<li class="chapter" data-level="8.3.12" data-path="080_vector.html"><a href="080_vector.html#begin"><i class="fa fa-check"></i><b>8.3.12</b> <code>begin()</code></a></li>
<li class="chapter" data-level="8.3.13" data-path="080_vector.html"><a href="080_vector.html#end"><i class="fa fa-check"></i><b>8.3.13</b> <code>end()</code></a></li>
<li class="chapter" data-level="8.3.14" data-path="080_vector.html"><a href="080_vector.html#cbegin"><i class="fa fa-check"></i><b>8.3.14</b> <code>cbegin()</code></a></li>
<li class="chapter" data-level="8.3.15" data-path="080_vector.html"><a href="080_vector.html#cend"><i class="fa fa-check"></i><b>8.3.15</b> <code>cend()</code></a></li>
<li class="chapter" data-level="8.3.16" data-path="080_vector.html"><a href="080_vector.html#insert-i-x"><i class="fa fa-check"></i><b>8.3.16</b> <code>insert( i, x )</code></a></li>
<li class="chapter" data-level="8.3.17" data-path="080_vector.html"><a href="080_vector.html#insert-it-x"><i class="fa fa-check"></i><b>8.3.17</b> <code>insert( it, x )</code></a></li>
<li class="chapter" data-level="8.3.18" data-path="080_vector.html"><a href="080_vector.html#erasei"><i class="fa fa-check"></i><b>8.3.18</b> <code>erase(i)</code></a></li>
<li class="chapter" data-level="8.3.19" data-path="080_vector.html"><a href="080_vector.html#eraseit"><i class="fa fa-check"></i><b>8.3.19</b> <code>erase(it)</code></a></li>
<li class="chapter" data-level="8.3.20" data-path="080_vector.html"><a href="080_vector.html#erase-first_i-last_i"><i class="fa fa-check"></i><b>8.3.20</b> <code>erase( first_i, last_i )</code></a></li>
<li class="chapter" data-level="8.3.21" data-path="080_vector.html"><a href="080_vector.html#erase-first_it-last_it"><i class="fa fa-check"></i><b>8.3.21</b> <code>erase( first_it, last_it )</code></a></li>
<li class="chapter" data-level="8.3.22" data-path="080_vector.html"><a href="080_vector.html#containselementnamedname"><i class="fa fa-check"></i><b>8.3.22</b> <code>containsElementNamed(name)</code></a></li>
</ul></li>
<li class="chapter" data-level="8.4" data-path="080_vector.html"><a href="080_vector.html#static-member-functions-vector"><i class="fa fa-check"></i><b>8.4</b> Static member functions</a>
<ul>
<li class="chapter" data-level="8.4.1" data-path="080_vector.html"><a href="080_vector.html#get_na"><i class="fa fa-check"></i><b>8.4.1</b> <code>get_na()</code></a></li>
<li class="chapter" data-level="8.4.2" data-path="080_vector.html"><a href="080_vector.html#is_nax"><i class="fa fa-check"></i><b>8.4.2</b> <code>is_na(x)</code></a></li>
<li class="chapter" data-level="8.4.3" data-path="080_vector.html"><a href="080_vector.html#create-x1-x2-..."><i class="fa fa-check"></i><b>8.4.3</b> <code>create( x1, x2, ...)</code></a></li>
<li class="chapter" data-level="8.4.4" data-path="080_vector.html"><a href="080_vector.html#import-first_it-last_it"><i class="fa fa-check"></i><b>8.4.4</b> <code>import( first_it , last_it )</code></a></li>
<li class="chapter" data-level="8.4.5" data-path="080_vector.html"><a href="080_vector.html#import_transform-first_it-last_it-func"><i class="fa fa-check"></i><b>8.4.5</b> <code>import_transform( first_it, last_it, func)</code></a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="9" data-path="100_matrix.html"><a href="100_matrix.html"><i class="fa fa-check"></i><b>9</b> Matrix</a>
<ul>
<li class="chapter" data-level="9.1" data-path="100_matrix.html"><a href="100_matrix.html#creating-matrix-object"><i class="fa fa-check"></i><b>9.1</b> Creating Matrix object</a></li>
<li class="chapter" data-level="9.2" data-path="100_matrix.html"><a href="100_matrix.html#accessing-to-matrix-elements"><i class="fa fa-check"></i><b>9.2</b> Accessing to Matrix elements</a>
<ul>
<li class="chapter" data-level="9.2.1" data-path="100_matrix.html"><a href="100_matrix.html#accessing-as-reference-to-row-column-and-sub-matrix"><i class="fa fa-check"></i><b>9.2.1</b> Accessing as reference to row, column and sub matrix</a></li>
</ul></li>
<li class="chapter" data-level="9.3" data-path="100_matrix.html"><a href="100_matrix.html#member-functions-matrix"><i class="fa fa-check"></i><b>9.3</b> Member functions</a>
<ul>
<li class="chapter" data-level="9.3.1" data-path="100_matrix.html"><a href="100_matrix.html#nrow-rows"><i class="fa fa-check"></i><b>9.3.1</b> nrow() rows()</a></li>
<li class="chapter" data-level="9.3.2" data-path="100_matrix.html"><a href="100_matrix.html#ncol-cols"><i class="fa fa-check"></i><b>9.3.2</b> ncol() cols()</a></li>
<li class="chapter" data-level="9.3.3" data-path="100_matrix.html"><a href="100_matrix.html#row-i"><i class="fa fa-check"></i><b>9.3.3</b> row( i )</a></li>
<li class="chapter" data-level="9.3.4" data-path="100_matrix.html"><a href="100_matrix.html#column-i"><i class="fa fa-check"></i><b>9.3.4</b> column( i )</a></li>
<li class="chapter" data-level="9.3.5" data-path="100_matrix.html"><a href="100_matrix.html#fill_diag-x"><i class="fa fa-check"></i><b>9.3.5</b> fill_diag( x )</a></li>
<li class="chapter" data-level="9.3.6" data-path="100_matrix.html"><a href="100_matrix.html#offset-i-j"><i class="fa fa-check"></i><b>9.3.6</b> offset( i, j )</a></li>
</ul></li>
<li class="chapter" data-level="9.4" data-path="100_matrix.html"><a href="100_matrix.html#static-member-functions-matrix"><i class="fa fa-check"></i><b>9.4</b> Static member functions</a>
<ul>
<li class="chapter" data-level="9.4.1" data-path="100_matrix.html"><a href="100_matrix.html#matrixdiag-size-x"><i class="fa fa-check"></i><b>9.4.1</b> Matrix::diag( size, x )</a></li>
</ul></li>
<li class="chapter" data-level="9.5" data-path="100_matrix.html"><a href="100_matrix.html#other-functions-related-to-matrix"><i class="fa fa-check"></i><b>9.5</b> Other functions related to Matrix</a>
<ul>
<li class="chapter" data-level="9.5.1" data-path="100_matrix.html"><a href="100_matrix.html#rownames-m"><i class="fa fa-check"></i><b>9.5.1</b> rownames( m )</a></li>
<li class="chapter" data-level="9.5.2" data-path="100_matrix.html"><a href="100_matrix.html#colnames-m"><i class="fa fa-check"></i><b>9.5.2</b> colnames( m )</a></li>
<li class="chapter" data-level="9.5.3" data-path="100_matrix.html"><a href="100_matrix.html#transpose-m"><i class="fa fa-check"></i><b>9.5.3</b> transpose( m )</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="10" data-path="110_calculation.html"><a href="110_calculation.html"><i class="fa fa-check"></i><b>10</b> Vector operations</a>
<ul>
<li class="chapter" data-level="10.1" data-path="110_calculation.html"><a href="110_calculation.html#arithmetic-operations"><i class="fa fa-check"></i><b>10.1</b> Arithmetic operations</a></li>
<li class="chapter" data-level="10.2" data-path="110_calculation.html"><a href="110_calculation.html#comparison-operations"><i class="fa fa-check"></i><b>10.2</b> Comparison operations</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="120_logical.html"><a href="120_logical.html"><i class="fa fa-check"></i><b>11</b> Logical operations</a>
<ul>
<li class="chapter" data-level="11.1" data-path="120_logical.html"><a href="120_logical.html#logicalvector"><i class="fa fa-check"></i><b>11.1</b> LogicalVector</a>
<ul>
<li class="chapter" data-level="11.1.1" data-path="120_logical.html"><a href="120_logical.html#data-type-of-logicalvector-elements"><i class="fa fa-check"></i><b>11.1.1</b> Data type of LogicalVector elements</a></li>
</ul></li>
<li class="chapter" data-level="11.2" data-path="120_logical.html"><a href="120_logical.html#logical-operations-1"><i class="fa fa-check"></i><b>11.2</b> Logical operations</a></li>
<li class="chapter" data-level="11.3" data-path="120_logical.html"><a href="120_logical.html#function-that-receives-logicalvector"><i class="fa fa-check"></i><b>11.3</b> Function that receives LogicalVector</a>
<ul>
<li class="chapter" data-level="11.3.1" data-path="120_logical.html"><a href="120_logical.html#all-any"><i class="fa fa-check"></i><b>11.3.1</b> all(), any()</a></li>
<li class="chapter" data-level="11.3.2" data-path="120_logical.html"><a href="120_logical.html#ifelse"><i class="fa fa-check"></i><b>11.3.2</b> ifelse()</a></li>
</ul></li>
<li class="chapter" data-level="11.4" data-path="120_logical.html"><a href="120_logical.html#evaluation-of-elements-of-logicalvector"><i class="fa fa-check"></i><b>11.4</b> Evaluation of elements of LogicalVector</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="140_dataframe.html"><a href="140_dataframe.html"><i class="fa fa-check"></i><b>12</b> DataFrame</a>
<ul>
<li class="chapter" data-level="12.1" data-path="140_dataframe.html"><a href="140_dataframe.html#creating-a-dataframe-object"><i class="fa fa-check"></i><b>12.1</b> Creating a DataFrame object</a></li>
<li class="chapter" data-level="12.2" data-path="140_dataframe.html"><a href="140_dataframe.html#accessing-dataframe-elements"><i class="fa fa-check"></i><b>12.2</b> Accessing DataFrame elements</a></li>
<li class="chapter" data-level="12.3" data-path="140_dataframe.html"><a href="140_dataframe.html#member-functions-data-frame"><i class="fa fa-check"></i><b>12.3</b> Member functions</a>
<ul>
<li class="chapter" data-level="12.3.1" data-path="140_dataframe.html"><a href="140_dataframe.html#length-size-1"><i class="fa fa-check"></i><b>12.3.1</b> length() size()</a></li>
<li class="chapter" data-level="12.3.2" data-path="140_dataframe.html"><a href="140_dataframe.html#nrows"><i class="fa fa-check"></i><b>12.3.2</b> nrows()</a></li>
<li class="chapter" data-level="12.3.3" data-path="140_dataframe.html"><a href="140_dataframe.html#names-1"><i class="fa fa-check"></i><b>12.3.3</b> names()</a></li>
<li class="chapter" data-level="12.3.4" data-path="140_dataframe.html"><a href="140_dataframe.html#offsetname-findnamename"><i class="fa fa-check"></i><b>12.3.4</b> offset(name) findName(name)</a></li>
<li class="chapter" data-level="12.3.5" data-path="140_dataframe.html"><a href="140_dataframe.html#fillv"><i class="fa fa-check"></i><b>12.3.5</b> fill(v)</a></li>
<li class="chapter" data-level="12.3.6" data-path="140_dataframe.html"><a href="140_dataframe.html#assign-first_it-last_it-1"><i class="fa fa-check"></i><b>12.3.6</b> assign( first_it, last_it)</a></li>
<li class="chapter" data-level="12.3.7" data-path="140_dataframe.html"><a href="140_dataframe.html#push_backv"><i class="fa fa-check"></i><b>12.3.7</b> push_back(v)</a></li>
<li class="chapter" data-level="12.3.8" data-path="140_dataframe.html"><a href="140_dataframe.html#push_back-v-name"><i class="fa fa-check"></i><b>12.3.8</b> push_back( v, name )</a></li>
<li class="chapter" data-level="12.3.9" data-path="140_dataframe.html"><a href="140_dataframe.html#push_frontx"><i class="fa fa-check"></i><b>12.3.9</b> push_front(x)</a></li>
<li class="chapter" data-level="12.3.10" data-path="140_dataframe.html"><a href="140_dataframe.html#push_front-x-name-1"><i class="fa fa-check"></i><b>12.3.10</b> push_front( x, name )</a></li>
<li class="chapter" data-level="12.3.11" data-path="140_dataframe.html"><a href="140_dataframe.html#begin-1"><i class="fa fa-check"></i><b>12.3.11</b> begin()</a></li>
<li class="chapter" data-level="12.3.12" data-path="140_dataframe.html"><a href="140_dataframe.html#end-1"><i class="fa fa-check"></i><b>12.3.12</b> end()</a></li>
<li class="chapter" data-level="12.3.13" data-path="140_dataframe.html"><a href="140_dataframe.html#insert-it-v"><i class="fa fa-check"></i><b>12.3.13</b> insert( it, v )</a></li>
<li class="chapter" data-level="12.3.14" data-path="140_dataframe.html"><a href="140_dataframe.html#erasei-1"><i class="fa fa-check"></i><b>12.3.14</b> erase(i)</a></li>
<li class="chapter" data-level="12.3.15" data-path="140_dataframe.html"><a href="140_dataframe.html#eraseit-1"><i class="fa fa-check"></i><b>12.3.15</b> erase(it)</a></li>
<li class="chapter" data-level="12.3.16" data-path="140_dataframe.html"><a href="140_dataframe.html#erasefirst_i-last_i"><i class="fa fa-check"></i><b>12.3.16</b> erase(first_i, last_i)</a></li>
<li class="chapter" data-level="12.3.17" data-path="140_dataframe.html"><a href="140_dataframe.html#erasefirst_it-last_it"><i class="fa fa-check"></i><b>12.3.17</b> erase(first_it, last_it)</a></li>
<li class="chapter" data-level="12.3.18" data-path="140_dataframe.html"><a href="140_dataframe.html#containselementnamedname-1"><i class="fa fa-check"></i><b>12.3.18</b> containsElementNamed(name)</a></li>
<li class="chapter" data-level="12.3.19" data-path="140_dataframe.html"><a href="140_dataframe.html#inheritsstr"><i class="fa fa-check"></i><b>12.3.19</b> inherits(str)</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="13" data-path="150_list.html"><a href="150_list.html"><i class="fa fa-check"></i><b>13</b> List</a>
<ul>
<li class="chapter" data-level="13.1" data-path="150_list.html"><a href="150_list.html#creating-list-object"><i class="fa fa-check"></i><b>13.1</b> Creating List object</a></li>
<li class="chapter" data-level="13.2" data-path="150_list.html"><a href="150_list.html#accessing-list-elements"><i class="fa fa-check"></i><b>13.2</b> Accessing List elements</a></li>
<li class="chapter" data-level="13.3" data-path="150_list.html"><a href="150_list.html#member-functions-list"><i class="fa fa-check"></i><b>13.3</b> Member functions</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="160_s3_s4.html"><a href="160_s3_s4.html"><i class="fa fa-check"></i><b>14</b> S3・S4 class</a>
<ul>
<li class="chapter" data-level="14.1" data-path="160_s3_s4.html"><a href="160_s3_s4.html#s3-class"><i class="fa fa-check"></i><b>14.1</b> S3 class</a></li>
<li class="chapter" data-level="14.2" data-path="160_s3_s4.html"><a href="160_s3_s4.html#s4-class"><i class="fa fa-check"></i><b>14.2</b> S4 class</a>
<ul>
<li class="chapter" data-level="14.2.1" data-path="160_s3_s4.html"><a href="160_s3_s4.html#accessing-to-slot"><i class="fa fa-check"></i><b>14.2.1</b> Accessing to slot</a></li>
<li class="chapter" data-level="14.2.2" data-path="160_s3_s4.html"><a href="160_s3_s4.html#creating-a-new-s4-class-object"><i class="fa fa-check"></i><b>14.2.2</b> Creating a new S4 class object</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="15" data-path="170_string.html"><a href="170_string.html"><i class="fa fa-check"></i><b>15</b> String</a>
<ul>
<li class="chapter" data-level="15.1" data-path="170_string.html"><a href="170_string.html#creating-string-object"><i class="fa fa-check"></i><b>15.1</b> Creating String object</a></li>
<li class="chapter" data-level="15.2" data-path="170_string.html"><a href="170_string.html#operators-string"><i class="fa fa-check"></i><b>15.2</b> Operators</a></li>
<li class="chapter" data-level="15.3" data-path="170_string.html"><a href="170_string.html#member-functions-string"><i class="fa fa-check"></i><b>15.3</b> Member functions</a>
<ul>
<li class="chapter" data-level="15.3.1" data-path="170_string.html"><a href="170_string.html#replace_first-str-new_str"><i class="fa fa-check"></i><b>15.3.1</b> replace_first( str, new_str )</a></li>
<li class="chapter" data-level="15.3.2" data-path="170_string.html"><a href="170_string.html#replace_last-str-new_str"><i class="fa fa-check"></i><b>15.3.2</b> replace_last( str, new_str )</a></li>
<li class="chapter" data-level="15.3.3" data-path="170_string.html"><a href="170_string.html#replace_all-str-new_str"><i class="fa fa-check"></i><b>15.3.3</b> replace_all( str, new_str )</a></li>
<li class="chapter" data-level="15.3.4" data-path="170_string.html"><a href="170_string.html#push_backstr"><i class="fa fa-check"></i><b>15.3.4</b> push_back(str)</a></li>
<li class="chapter" data-level="15.3.5" data-path="170_string.html"><a href="170_string.html#push_frontstr"><i class="fa fa-check"></i><b>15.3.5</b> push_front(str)</a></li>
<li class="chapter" data-level="15.3.6" data-path="170_string.html"><a href="170_string.html#set_na"><i class="fa fa-check"></i><b>15.3.6</b> set_na()</a></li>
<li class="chapter" data-level="15.3.7" data-path="170_string.html"><a href="170_string.html#get_cstring"><i class="fa fa-check"></i><b>15.3.7</b> get_cstring()</a></li>
<li class="chapter" data-level="15.3.8" data-path="170_string.html"><a href="170_string.html#get_encoding"><i class="fa fa-check"></i><b>15.3.8</b> get_encoding()</a></li>
<li class="chapter" data-level="15.3.9" data-path="170_string.html"><a href="170_string.html#set_encodingenc"><i class="fa fa-check"></i><b>15.3.9</b> set_encoding(enc)</a></li>
<li class="chapter" data-level="15.3.10" data-path="170_string.html"><a href="170_string.html#code-example-string"><i class="fa fa-check"></i><b>15.3.10</b> Code example</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="16" data-path="180_date.html"><a href="180_date.html"><i class="fa fa-check"></i><b>16</b> Date and DateVector</a>
<ul>
<li class="chapter" data-level="16.1" data-path="180_date.html"><a href="180_date.html#creating-date-objects"><i class="fa fa-check"></i><b>16.1</b> Creating Date objects</a></li>
<li class="chapter" data-level="16.2" data-path="180_date.html"><a href="180_date.html#operators-date"><i class="fa fa-check"></i><b>16.2</b> Operators</a></li>
<li class="chapter" data-level="16.3" data-path="180_date.html"><a href="180_date.html#member-functions-date"><i class="fa fa-check"></i><b>16.3</b> Member functions</a>
<ul>
<li class="chapter" data-level="16.3.1" data-path="180_date.html"><a href="180_date.html#format"><i class="fa fa-check"></i><b>16.3.1</b> format()</a></li>
<li class="chapter" data-level="16.3.2" data-path="180_date.html"><a href="180_date.html#getday"><i class="fa fa-check"></i><b>16.3.2</b> getDay()</a></li>
<li class="chapter" data-level="16.3.3" data-path="180_date.html"><a href="180_date.html#getmonth"><i class="fa fa-check"></i><b>16.3.3</b> getMonth()</a></li>
<li class="chapter" data-level="16.3.4" data-path="180_date.html"><a href="180_date.html#getyear"><i class="fa fa-check"></i><b>16.3.4</b> getYear()</a></li>
<li class="chapter" data-level="16.3.5" data-path="180_date.html"><a href="180_date.html#getweekday"><i class="fa fa-check"></i><b>16.3.5</b> getWeekday()</a></li>
<li class="chapter" data-level="16.3.6" data-path="180_date.html"><a href="180_date.html#getyearday"><i class="fa fa-check"></i><b>16.3.6</b> getYearday()</a></li>
<li class="chapter" data-level="16.3.7" data-path="180_date.html"><a href="180_date.html#is_na"><i class="fa fa-check"></i><b>16.3.7</b> is_na()</a></li>
</ul></li>
<li class="chapter" data-level="16.4" data-path="180_date.html"><a href="180_date.html#execution-result-date"><i class="fa fa-check"></i><b>16.4</b> Execution result</a></li>
<li class="chapter" data-level="16.5" data-path="180_date.html"><a href="180_date.html#datevector-subsetting"><i class="fa fa-check"></i><b>16.5</b> DateVector subsetting</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="190_datetime.html"><a href="190_datetime.html"><i class="fa fa-check"></i><b>17</b> Datetime</a>
<ul>
<li class="chapter" data-level="17.1" data-path="190_datetime.html"><a href="190_datetime.html#creating-datetime-object"><i class="fa fa-check"></i><b>17.1</b> Creating Datetime object</a></li>
<li class="chapter" data-level="17.2" data-path="190_datetime.html"><a href="190_datetime.html#time-zone"><i class="fa fa-check"></i><b>17.2</b> Time zone</a></li>
<li class="chapter" data-level="17.3" data-path="190_datetime.html"><a href="190_datetime.html#operators-datetime"><i class="fa fa-check"></i><b>17.3</b> Operators</a></li>
<li class="chapter" data-level="17.4" data-path="190_datetime.html"><a href="190_datetime.html#member-functions-datetime"><i class="fa fa-check"></i><b>17.4</b> Member functions</a>
<ul>
<li class="chapter" data-level="17.4.1" data-path="190_datetime.html"><a href="190_datetime.html#getfractionaltimestamp"><i class="fa fa-check"></i><b>17.4.1</b> getFractionalTimestamp()</a></li>
<li class="chapter" data-level="17.4.2" data-path="190_datetime.html"><a href="190_datetime.html#getmicroseconds"><i class="fa fa-check"></i><b>17.4.2</b> getMicroSeconds()</a></li>
<li class="chapter" data-level="17.4.3" data-path="190_datetime.html"><a href="190_datetime.html#getseconds"><i class="fa fa-check"></i><b>17.4.3</b> getSeconds()</a></li>
<li class="chapter" data-level="17.4.4" data-path="190_datetime.html"><a href="190_datetime.html#getminutes"><i class="fa fa-check"></i><b>17.4.4</b> getMinutes()</a></li>
<li class="chapter" data-level="17.4.5" data-path="190_datetime.html"><a href="190_datetime.html#gethours"><i class="fa fa-check"></i><b>17.4.5</b> getHours()</a></li>
<li class="chapter" data-level="17.4.6" data-path="190_datetime.html"><a href="190_datetime.html#getday-1"><i class="fa fa-check"></i><b>17.4.6</b> getDay()</a></li>
<li class="chapter" data-level="17.4.7" data-path="190_datetime.html"><a href="190_datetime.html#getmonth-1"><i class="fa fa-check"></i><b>17.4.7</b> getMonth()</a></li>
<li class="chapter" data-level="17.4.8" data-path="190_datetime.html"><a href="190_datetime.html#getyear-1"><i class="fa fa-check"></i><b>17.4.8</b> getYear()</a></li>
<li class="chapter" data-level="17.4.9" data-path="190_datetime.html"><a href="190_datetime.html#getweekday-1"><i class="fa fa-check"></i><b>17.4.9</b> getWeekday()</a></li>
<li class="chapter" data-level="17.4.10" data-path="190_datetime.html"><a href="190_datetime.html#getyearday-1"><i class="fa fa-check"></i><b>17.4.10</b> getYearday()</a></li>
<li class="chapter" data-level="17.4.11" data-path="190_datetime.html"><a href="190_datetime.html#is_na-1"><i class="fa fa-check"></i><b>17.4.11</b> is_na()</a></li>
</ul></li>
<li class="chapter" data-level="17.5" data-path="190_datetime.html"><a href="190_datetime.html#code-example-datetime"><i class="fa fa-check"></i><b>17.5</b> Code example</a></li>
</ul></li>
<li class="chapter" data-level="18" data-path="200_robject.html"><a href="200_robject.html"><i class="fa fa-check"></i><b>18</b> RObject</a>
<ul>
<li class="chapter" data-level="18.1" data-path="200_robject.html"><a href="200_robject.html#member-functions"><i class="fa fa-check"></i><b>18.1</b> Member functions</a>
<ul>
<li class="chapter" data-level="18.1.1" data-path="200_robject.html"><a href="200_robject.html#inheritsstr-1"><i class="fa fa-check"></i><b>18.1.1</b> inherits(str)</a></li>
<li class="chapter" data-level="18.1.2" data-path="200_robject.html"><a href="200_robject.html#slotname"><i class="fa fa-check"></i><b>18.1.2</b> slot(name)</a></li>
<li class="chapter" data-level="18.1.3" data-path="200_robject.html"><a href="200_robject.html#hasslotname"><i class="fa fa-check"></i><b>18.1.3</b> hasSlot(name)</a></li>
<li class="chapter" data-level="18.1.4" data-path="200_robject.html"><a href="200_robject.html#attrname"><i class="fa fa-check"></i><b>18.1.4</b> attr(name)</a></li>
<li class="chapter" data-level="18.1.5" data-path="200_robject.html"><a href="200_robject.html#attributenames"><i class="fa fa-check"></i><b>18.1.5</b> attributeNames()</a></li>
<li class="chapter" data-level="18.1.6" data-path="200_robject.html"><a href="200_robject.html#hasattributename"><i class="fa fa-check"></i><b>18.1.6</b> hasAttribute(name)</a></li>
<li class="chapter" data-level="18.1.7" data-path="200_robject.html"><a href="200_robject.html#isnull"><i class="fa fa-check"></i><b>18.1.7</b> isNULL()</a></li>
<li class="chapter" data-level="18.1.8" data-path="200_robject.html"><a href="200_robject.html#sexp_type"><i class="fa fa-check"></i><b>18.1.8</b> sexp_type()</a></li>
<li class="chapter" data-level="18.1.9" data-path="200_robject.html"><a href="200_robject.html#isobject"><i class="fa fa-check"></i><b>18.1.9</b> isObject()</a></li>
<li class="chapter" data-level="18.1.10" data-path="200_robject.html"><a href="200_robject.html#iss4"><i class="fa fa-check"></i><b>18.1.10</b> isS4()</a></li>
</ul></li>
<li class="chapter" data-level="18.2" data-path="200_robject.html"><a href="200_robject.html#determining-type-of-object-assigned-to-robject"><i class="fa fa-check"></i><b>18.2</b> Determining type of object assigned to RObject</a></li>
<li class="chapter" data-level="18.3" data-path="200_robject.html"><a href="200_robject.html#using-robject-to-write-functions-that-receive-various-datatypes-function-templates"><i class="fa fa-check"></i><b>18.3</b> Using <code>RObject</code> to write functions that receive various datatypes (function templates)</a></li>
</ul></li>
<li class="chapter" data-level="19" data-path="201_caution_vector.html"><a href="201_caution_vector.html"><i class="fa fa-check"></i><b>19</b> Cautions in handling Rcpp objects</a>
<ul>
<li class="chapter" data-level="19.1" data-path="201_caution_vector.html"><a href="201_caution_vector.html#assigning-between-vectors"><i class="fa fa-check"></i><b>19.1</b> Assigning between vectors</a></li>
<li class="chapter" data-level="19.2" data-path="201_caution_vector.html"><a href="201_caution_vector.html#data-type-of-numerical-index"><i class="fa fa-check"></i><b>19.2</b> Data type of numerical index</a></li>
<li class="chapter" data-level="19.3" data-path="201_caution_vector.html"><a href="201_caution_vector.html#return-type-of-operator"><i class="fa fa-check"></i><b>19.3</b> Return type of operator[]</a></li>
</ul></li>
<li class="chapter" data-level="20" data-path="202_attributes.html"><a href="202_attributes.html"><i class="fa fa-check"></i><b>20</b> Attributes</a>
<ul>
<li class="chapter" data-level="20.1" data-path="202_attributes.html"><a href="202_attributes.html#attributes-related-functions"><i class="fa fa-check"></i><b>20.1</b> Attributes related functions</a></li>
<li class="chapter" data-level="20.2" data-path="202_attributes.html"><a href="202_attributes.html#access-functions-for-common-attributes"><i class="fa fa-check"></i><b>20.2</b> Access functions for common attributes</a></li>
</ul></li>
<li class="chapter" data-level="21" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html"><i class="fa fa-check"></i><b>21</b> R-like functions</a>
<ul>
<li class="chapter" data-level="21.1" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#list-of-r-like-functions"><i class="fa fa-check"></i><b>21.1</b> List of R-like functions</a>
<ul>
<li class="chapter" data-level="21.1.1" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#vector-related-functions"><i class="fa fa-check"></i><b>21.1.1</b> Vector related functions</a></li>
<li class="chapter" data-level="21.1.2" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#string-related-functions"><i class="fa fa-check"></i><b>21.1.2</b> String related functions</a></li>
<li class="chapter" data-level="21.1.3" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#finding-values"><i class="fa fa-check"></i><b>21.1.3</b> Finding values</a></li>
<li class="chapter" data-level="21.1.4" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#duplicated-values"><i class="fa fa-check"></i><b>21.1.4</b> Duplicated values</a></li>
<li class="chapter" data-level="21.1.5" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#set-operation"><i class="fa fa-check"></i><b>21.1.5</b> Set operation</a></li>
<li class="chapter" data-level="21.1.6" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#functions-related-to-maximum-and-minimum-values"><i class="fa fa-check"></i><b>21.1.6</b> Functions related to maximum and minimum values</a></li>
<li class="chapter" data-level="21.1.7" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#functions-related-to-summaries"><i class="fa fa-check"></i><b>21.1.7</b> Functions related to summaries</a></li>
<li class="chapter" data-level="21.1.8" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#functions-related-to-rounding-values"><i class="fa fa-check"></i><b>21.1.8</b> Functions related to rounding values</a></li>
<li class="chapter" data-level="21.1.9" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#functions-related-to-math"><i class="fa fa-check"></i><b>21.1.9</b> Functions related to math</a></li>
<li class="chapter" data-level="21.1.10" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#functions-related-to-logical-values"><i class="fa fa-check"></i><b>21.1.10</b> Functions related to logical values</a></li>
<li class="chapter" data-level="21.1.11" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#functions-related-to-na-inf-nan"><i class="fa fa-check"></i><b>21.1.11</b> Functions related to NA Inf NaN</a></li>
<li class="chapter" data-level="21.1.12" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#apply-functions"><i class="fa fa-check"></i><b>21.1.12</b> apply functions</a></li>
<li class="chapter" data-level="21.1.13" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#cbind-function"><i class="fa fa-check"></i><b>21.1.13</b> cbind function</a></li>
<li class="chapter" data-level="21.1.14" data-path="210_rcpp_functions.html"><a href="210_rcpp_functions.html#sampling"><i class="fa fa-check"></i><b>21.1.14</b> sampling</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="22" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html"><i class="fa fa-check"></i><b>22</b> Probability distribution</a>
<ul>
<li class="chapter" data-level="22.1" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#basic-structure-of-probability-distribution-function"><i class="fa fa-check"></i><b>22.1</b> Basic structure of probability distribution function</a></li>
<li class="chapter" data-level="22.2" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#list-of-probability-distribution-functions"><i class="fa fa-check"></i><b>22.2</b> List of probability distribution functions</a>
<ul>
<li class="chapter" data-level="22.2.1" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#continuous-probability-distribution"><i class="fa fa-check"></i><b>22.2.1</b> Continuous probability distribution</a></li>
<li class="chapter" data-level="22.2.2" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#discrete-probability-distribution"><i class="fa fa-check"></i><b>22.2.2</b> Discrete probability distribution</a></li>
</ul></li>
<li class="chapter" data-level="22.3" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#continuous-probability-distribution-1"><i class="fa fa-check"></i><b>22.3</b> Continuous probability distribution</a>
<ul>
<li class="chapter" data-level="22.3.1" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#uniform-distribution"><i class="fa fa-check"></i><b>22.3.1</b> Uniform distribution</a></li>
<li class="chapter" data-level="22.3.2" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#normal-distribution"><i class="fa fa-check"></i><b>22.3.2</b> Normal distribution</a></li>
<li class="chapter" data-level="22.3.3" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#log-normal-distribution"><i class="fa fa-check"></i><b>22.3.3</b> Log-normal distribution</a></li>
<li class="chapter" data-level="22.3.4" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#gamma-distribution"><i class="fa fa-check"></i><b>22.3.4</b> Gamma distribution</a></li>
<li class="chapter" data-level="22.3.5" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#beta-distribution"><i class="fa fa-check"></i><b>22.3.5</b> Beta distribution</a></li>
<li class="chapter" data-level="22.3.6" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#noncentral-beta-distribution"><i class="fa fa-check"></i><b>22.3.6</b> Noncentral beta distribution</a></li>
<li class="chapter" data-level="22.3.7" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#chi-squared-distribution"><i class="fa fa-check"></i><b>22.3.7</b> Chi-squared distribution</a></li>
<li class="chapter" data-level="22.3.8" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#noncentral-chi-squared-distribution"><i class="fa fa-check"></i><b>22.3.8</b> Noncentral chi-squared distribution</a></li>
<li class="chapter" data-level="22.3.9" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#t-distribution"><i class="fa fa-check"></i><b>22.3.9</b> t-distribution</a></li>
<li class="chapter" data-level="22.3.10" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#noncentral-t-distribution"><i class="fa fa-check"></i><b>22.3.10</b> Noncentral t-distribution</a></li>
<li class="chapter" data-level="22.3.11" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#f-distribution"><i class="fa fa-check"></i><b>22.3.11</b> F-distribution</a></li>
<li class="chapter" data-level="22.3.12" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#noncentral-f-distribution"><i class="fa fa-check"></i><b>22.3.12</b> Noncentral F-distribution</a></li>
<li class="chapter" data-level="22.3.13" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#cauchy-distribution"><i class="fa fa-check"></i><b>22.3.13</b> Cauchy distribution</a></li>
<li class="chapter" data-level="22.3.14" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#exponential-distribution"><i class="fa fa-check"></i><b>22.3.14</b> Exponential distribution</a></li>
<li class="chapter" data-level="22.3.15" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#logistic-distribution"><i class="fa fa-check"></i><b>22.3.15</b> Logistic distribution</a></li>
<li class="chapter" data-level="22.3.16" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#weibull-distribution"><i class="fa fa-check"></i><b>22.3.16</b> Weibull distribution</a></li>
</ul></li>
<li class="chapter" data-level="22.4" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#discrete-probability-distribution-1"><i class="fa fa-check"></i><b>22.4</b> Discrete probability distribution</a>
<ul>
<li class="chapter" data-level="22.4.1" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#binomial-distribution"><i class="fa fa-check"></i><b>22.4.1</b> Binomial distribution</a></li>
<li class="chapter" data-level="22.4.2" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#negative-binomial-distribution-with-success-probability-as-parameter"><i class="fa fa-check"></i><b>22.4.2</b> Negative binomial distribution (with success probability as parameter)</a></li>
<li class="chapter" data-level="22.4.3" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#negative-binomial-distribution-with-mean-as-parameter"><i class="fa fa-check"></i><b>22.4.3</b> Negative binomial distribution (with mean as parameter)</a></li>
<li class="chapter" data-level="22.4.4" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#poisson-distribution"><i class="fa fa-check"></i><b>22.4.4</b> Poisson distribution</a></li>
<li class="chapter" data-level="22.4.5" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#geometric-distribution"><i class="fa fa-check"></i><b>22.4.5</b> Geometric distribution</a></li>
<li class="chapter" data-level="22.4.6" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#hypergeometric-distribution"><i class="fa fa-check"></i><b>22.4.6</b> Hypergeometric distribution</a></li>
<li class="chapter" data-level="22.4.7" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#distribution-of-wilcoxon-rank-sum-test-statistic"><i class="fa fa-check"></i><b>22.4.7</b> Distribution of Wilcoxon rank-sum test statistic</a></li>
<li class="chapter" data-level="22.4.8" data-path="220_dpqr_functions.html"><a href="220_dpqr_functions.html#distribution-of-wilcoxon-signed-rank-test-statistic"><i class="fa fa-check"></i><b>22.4.8</b> Distribution of Wilcoxon signed-rank test statistic</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="23" data-path="230_R_function.html"><a href="230_R_function.html"><i class="fa fa-check"></i><b>23</b> Using R functions</a>
<ul>
<li class="chapter" data-level="23.1" data-path="230_R_function.html"><a href="230_R_function.html#function"><i class="fa fa-check"></i><b>23.1</b> Function</a></li>
<li class="chapter" data-level="23.2" data-path="230_R_function.html"><a href="230_R_function.html#environment"><i class="fa fa-check"></i><b>23.2</b> Environment</a></li>
</ul></li>
<li class="chapter" data-level="24" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html"><i class="fa fa-check"></i><b>24</b> NA NaN Inf NULL</a>
<ul>
<li class="chapter" data-level="24.1" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html#notations-of-na-nan-inf"><i class="fa fa-check"></i><b>24.1</b> Notations of NA NaN Inf</a></li>
<li class="chapter" data-level="24.2" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html#evaluating-na-nan-inf"><i class="fa fa-check"></i><b>24.2</b> Evaluating NA NaN Inf</a>
<ul>
<li class="chapter" data-level="24.2.1" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html#evaluating-all-the-elements-of-a-vector-at-once"><i class="fa fa-check"></i><b>24.2.1</b> Evaluating all the elements of a vector at once</a></li>
<li class="chapter" data-level="24.2.2" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html#evaluating-single-element-of-a-vector"><i class="fa fa-check"></i><b>24.2.2</b> Evaluating single element of a vector</a></li>
</ul></li>
<li class="chapter" data-level="24.3" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html#null"><i class="fa fa-check"></i><b>24.3</b> NULL</a></li>
<li class="chapter" data-level="24.4" data-path="240_na_nan_inf.html"><a href="240_na_nan_inf.html#points-to-note-when-handling-na-with-rcpp"><i class="fa fa-check"></i><b>24.4</b> Points to note when handling NA with Rcpp</a></li>
</ul></li>
<li class="chapter" data-level="25" data-path="250_factor.html"><a href="250_factor.html"><i class="fa fa-check"></i><b>25</b> factor</a></li>
<li class="chapter" data-level="26" data-path="260_error.html"><a href="260_error.html"><i class="fa fa-check"></i><b>26</b> Error handling</a></li>
<li class="chapter" data-level="27" data-path="270_cancellation.html"><a href="270_cancellation.html"><i class="fa fa-check"></i><b>27</b> Cancel handling</a></li>
<li class="chapter" data-level="28" data-path="280_environment.html"><a href="280_environment.html"><i class="fa fa-check"></i><b>28</b> Environment</a>
<ul>
<li class="chapter" data-level="28.1" data-path="280_environment.html"><a href="280_environment.html#creating-environment-object"><i class="fa fa-check"></i><b>28.1</b> Creating Environment object</a></li>
<li class="chapter" data-level="28.2" data-path="280_environment.html"><a href="280_environment.html#accessing-object-in-a-environment"><i class="fa fa-check"></i><b>28.2</b> Accessing object in a environment</a></li>
<li class="chapter" data-level="28.3" data-path="280_environment.html"><a href="280_environment.html#creating-new-environment"><i class="fa fa-check"></i><b>28.3</b> Creating new environment</a>
<ul>
<li class="chapter" data-level="28.3.1" data-path="280_environment.html"><a href="280_environment.html#new_envsize-29"><i class="fa fa-check"></i><b>28.3.1</b> new_env(size = 29)</a></li>
<li class="chapter" data-level="28.3.2" data-path="280_environment.html"><a href="280_environment.html#new_envparent-size-29"><i class="fa fa-check"></i><b>28.3.2</b> new_env(parent, size = 29)</a></li>
</ul></li>
<li class="chapter" data-level="28.4" data-path="280_environment.html"><a href="280_environment.html#member-functions-1"><i class="fa fa-check"></i><b>28.4</b> Member functions</a>
<ul>
<li class="chapter" data-level="28.4.1" data-path="280_environment.html"><a href="280_environment.html#getname"><i class="fa fa-check"></i><b>28.4.1</b> get(name)</a></li>
<li class="chapter" data-level="28.4.2" data-path="280_environment.html"><a href="280_environment.html#lsall"><i class="fa fa-check"></i><b>28.4.2</b> ls(all)</a></li>
<li class="chapter" data-level="28.4.3" data-path="280_environment.html"><a href="280_environment.html#findname"><i class="fa fa-check"></i><b>28.4.3</b> find(name)</a></li>
<li class="chapter" data-level="28.4.4" data-path="280_environment.html"><a href="280_environment.html#existsname"><i class="fa fa-check"></i><b>28.4.4</b> exists(name)</a></li>
<li class="chapter" data-level="28.4.5" data-path="280_environment.html"><a href="280_environment.html#assign-name-x"><i class="fa fa-check"></i><b>28.4.5</b> assign( name, x )</a></li>
<li class="chapter" data-level="28.4.6" data-path="280_environment.html"><a href="280_environment.html#islocked"><i class="fa fa-check"></i><b>28.4.6</b> isLocked()</a></li>
<li class="chapter" data-level="28.4.7" data-path="280_environment.html"><a href="280_environment.html#removename"><i class="fa fa-check"></i><b>28.4.7</b> remove(name)</a></li>
<li class="chapter" data-level="28.4.8" data-path="280_environment.html"><a href="280_environment.html#lockbindings-false"><i class="fa fa-check"></i><b>28.4.8</b> lock(bindings = false)</a></li>
<li class="chapter" data-level="28.4.9" data-path="280_environment.html"><a href="280_environment.html#lockbindingname"><i class="fa fa-check"></i><b>28.4.9</b> lockBinding(name)</a></li>
<li class="chapter" data-level="28.4.10" data-path="280_environment.html"><a href="280_environment.html#unlockbindingname"><i class="fa fa-check"></i><b>28.4.10</b> unlockBinding(name){</a></li>
<li class="chapter" data-level="28.4.11" data-path="280_environment.html"><a href="280_environment.html#bindingislockedname"><i class="fa fa-check"></i><b>28.4.11</b> bindingIsLocked(name)</a></li>
<li class="chapter" data-level="28.4.12" data-path="280_environment.html"><a href="280_environment.html#bindingisactivename"><i class="fa fa-check"></i><b>28.4.12</b> bindingIsActive(name)</a></li>
<li class="chapter" data-level="28.4.13" data-path="280_environment.html"><a href="280_environment.html#is_user_database"><i class="fa fa-check"></i><b>28.4.13</b> is_user_database()</a></li>
<li class="chapter" data-level="28.4.14" data-path="280_environment.html"><a href="280_environment.html#parent"><i class="fa fa-check"></i><b>28.4.14</b> parent()</a></li>
<li class="chapter" data-level="28.4.15" data-path="280_environment.html"><a href="280_environment.html#new_childhashed"><i class="fa fa-check"></i><b>28.4.15</b> new_child(hashed)</a></li>
</ul></li>
<li class="chapter" data-level="28.5" data-path="280_environment.html"><a href="280_environment.html#static-member-functions"><i class="fa fa-check"></i><b>28.5</b> Static member functions</a>
<ul>
<li class="chapter" data-level="28.5.1" data-path="280_environment.html"><a href="280_environment.html#environmentrcpp_namespace"><i class="fa fa-check"></i><b>28.5.1</b> Environment::Rcpp_namespace()</a></li>
<li class="chapter" data-level="28.5.2" data-path="280_environment.html"><a href="280_environment.html#environmentnamespace_envpackage"><i class="fa fa-check"></i><b>28.5.2</b> Environment::namespace_env(package)</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="29" data-path="290_iterator.html"><a href="290_iterator.html"><i class="fa fa-check"></i><b>29</b> Iterator</a></li>
<li class="chapter" data-level="30" data-path="300_STL.html"><a href="300_STL.html"><i class="fa fa-check"></i><b>30</b> Standard C data structures and algorithms</a>
<ul>
<li class="chapter" data-level="30.1" data-path="300_STL.html"><a href="300_STL.html#standard-c-data-structure"><i class="fa fa-check"></i><b>30.1</b> Standard C data structure</a></li>
<li class="chapter" data-level="30.2" data-path="300_STL.html"><a href="300_STL.html#conversion-between-standard-c-data-structures-and-rcpp-data-structures"><i class="fa fa-check"></i><b>30.2</b> Conversion between standard C data structures and Rcpp data structures</a></li>
<li class="chapter" data-level="30.3" data-path="300_STL.html"><a href="300_STL.html#use-standard-c-data-structures-as-arguments-and-return-values-of-rcpp-functions"><i class="fa fa-check"></i><b>30.3</b> Use standard C data structures as arguments and return values of Rcpp functions</a></li>
<li class="chapter" data-level="30.4" data-path="300_STL.html"><a href="300_STL.html#standard-c-algorithms"><i class="fa fa-check"></i><b>30.4</b> Standard C Algorithms</a></li>
</ul></li>
<li class="chapter" data-level="31" data-path="310_Rmath.html"><a href="310_Rmath.html"><i class="fa fa-check"></i><b>31</b> R Math Library</a></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Rcpp for everyone</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="using-r-functions" class="section level1" number="23">
<h1><span class="header-section-number">Chapter 23</span> Using R functions</h1>
<p>In order to use R functions in Rcpp, you can use <code>Function</code> and <code>Environment</code>.</p>
<div id="function" class="section level2" number="23.1">
<h2><span class="header-section-number">23.1</span> Function</h2>
<p>Using the <code>Function</code> class, you can call R functions from Rcpp. The argument given to the R function is determined based on position and name.</p>
<p>Use <code>Named()</code> or <code>_[]</code> to pass a value to an argument by specifying argument name. <code>Name()</code> can be used in two ways: <code>Named("argument_name", value)</code> or <code>Named("argument_name") = value</code>.</p>
<p>The code example below shows an example of calling the R function <code>rnorm (n, mean, sd)</code>from the function defined in Rcpp. However, when calling a package function using <code>Function</code> class, you have to add the package environment to the search path using the <code>library()</code> function in R in advance.</p>
<div class="sourceCode" id="cb113"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb113-1"><a href="230_R_function.html#cb113-1"></a><span class="co">// [[Rcpp::export]]</span></span>
<span id="cb113-2"><a href="230_R_function.html#cb113-2"></a>NumericVector my_fun(){</span>
<span id="cb113-3"><a href="230_R_function.html#cb113-3"></a> <span class="co">// calling rnorm()</span></span>
<span id="cb113-4"><a href="230_R_function.html#cb113-4"></a> Function f(<span class="st">"rnorm"</span>); </span>
<span id="cb113-5"><a href="230_R_function.html#cb113-5"></a></span>
<span id="cb113-6"><a href="230_R_function.html#cb113-6"></a> <span class="co">// Next code is interpreted as rnorm(n=5, mean=10, sd=2)</span></span>
<span id="cb113-7"><a href="230_R_function.html#cb113-7"></a> <span class="cf">return</span> f(<span class="dv">5</span>, Named(<span class="st">"sd"</span>)=<span class="dv">2</span>, _[<span class="st">"mean"</span>]=<span class="dv">10</span>);</span>
<span id="cb113-8"><a href="230_R_function.html#cb113-8"></a>}</span></code></pre></div>
<p>Execution example</p>
<div class="sourceCode" id="cb114"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb114-1"><a href="230_R_function.html#cb114-1"></a><span class="op">></span><span class="st"> </span><span class="kw">my_fun</span>()</span>
<span id="cb114-2"><a href="230_R_function.html#cb114-2"></a>[<span class="dv">1</span>] <span class="fl">8.014863</span> <span class="fl">10.459980</span> <span class="fl">7.741581</span> <span class="fl">9.000762</span> <span class="fl">11.465920</span></span></code></pre></div>
<p>In the above example, the return type of R function called from Rcpp is assumed <code>NumericVector</code>. However, as in the example below, the return type of an R function called from Rcpp function is sometimes undefined. In such a case it would be better to assign the return value of the function into <code>RObject</code> or <code>List</code> element.</p>
<p>The code below shows an example of defining simplified R function <code>lapply()</code> with Rcpp.</p>
<div class="sourceCode" id="cb115"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb115-1"><a href="230_R_function.html#cb115-1"></a><span class="co">// [[Rcpp::export]]</span></span>
<span id="cb115-2"><a href="230_R_function.html#cb115-2"></a>List rcpp_lapply(List input, Function f) {</span>
<span id="cb115-3"><a href="230_R_function.html#cb115-3"></a> <span class="co">// Applies the Function f to each element of the List input and returns the result as List</span></span>
<span id="cb115-4"><a href="230_R_function.html#cb115-4"></a></span>
<span id="cb115-5"><a href="230_R_function.html#cb115-5"></a> <span class="co">// Number of elements in the List input</span></span>
<span id="cb115-6"><a href="230_R_function.html#cb115-6"></a> <span class="dt">R_xlen_t</span> n = input.length();</span>
<span id="cb115-7"><a href="230_R_function.html#cb115-7"></a></span>
<span id="cb115-8"><a href="230_R_function.html#cb115-8"></a> <span class="co">// Creating a List for output</span></span>
<span id="cb115-9"><a href="230_R_function.html#cb115-9"></a> List out(n);</span>
<span id="cb115-10"><a href="230_R_function.html#cb115-10"></a></span>
<span id="cb115-11"><a href="230_R_function.html#cb115-11"></a> <span class="co">// Applying f() to each element of "input" and store it to "out".</span></span>
<span id="cb115-12"><a href="230_R_function.html#cb115-12"></a> <span class="co">// The type of the return value of f() is unknown, but it can be assigned to the List element.</span></span>
<span id="cb115-13"><a href="230_R_function.html#cb115-13"></a> <span class="cf">for</span>(<span class="dt">R_xlen_t</span> i = <span class="dv">0</span>; i < n; i) {</span>
<span id="cb115-14"><a href="230_R_function.html#cb115-14"></a> out[i] = f(input[i]);</span>
<span id="cb115-15"><a href="230_R_function.html#cb115-15"></a> }</span>
<span id="cb115-16"><a href="230_R_function.html#cb115-16"></a> <span class="cf">return</span> out;</span>
<span id="cb115-17"><a href="230_R_function.html#cb115-17"></a>}</span></code></pre></div>
</div>
<div id="environment" class="section level2" number="23.2">
<h2><span class="header-section-number">23.2</span> Environment</h2>
<p>By using <code>Environment</code> class, you can retrieve objects (variables and functions) from packages and other environments.</p>
<p>The code below shows an example of calling <code>Matrix()</code> function in the <code>Matrix</code> package. When calling a package function in this way, it is not necessary to attach the package using <code>library()</code> function.</p>
<div class="sourceCode" id="cb116"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb116-1"><a href="230_R_function.html#cb116-1"></a><span class="co">// [[Rcpp::export]]</span></span>
<span id="cb116-2"><a href="230_R_function.html#cb116-2"></a>S4 rcpp_package_function(NumericMatrix m){</span>
<span id="cb116-3"><a href="230_R_function.html#cb116-3"></a></span>
<span id="cb116-4"><a href="230_R_function.html#cb116-4"></a> <span class="co">// Obtaining namespace of Matrix package</span></span>
<span id="cb116-5"><a href="230_R_function.html#cb116-5"></a> Environment pkg = Environment::namespace_env(<span class="st">"Matrix"</span>);</span>
<span id="cb116-6"><a href="230_R_function.html#cb116-6"></a></span>
<span id="cb116-7"><a href="230_R_function.html#cb116-7"></a> <span class="co">// Picking up Matrix() function from Matrix package</span></span>
<span id="cb116-8"><a href="230_R_function.html#cb116-8"></a> Function f = pkg[<span class="st">"Matrix"</span>];</span>
<span id="cb116-9"><a href="230_R_function.html#cb116-9"></a></span>
<span id="cb116-10"><a href="230_R_function.html#cb116-10"></a> <span class="co">// Executing Matrix( m, sparse = TRIE )</span></span>
<span id="cb116-11"><a href="230_R_function.html#cb116-11"></a> <span class="cf">return</span> f( m, Named(<span class="st">"sparse"</span>, <span class="kw">true</span>));</span>
<span id="cb116-12"><a href="230_R_function.html#cb116-12"></a>}</span></code></pre></div>
<p>Execution result</p>
<pre><code>> m <- matrix(c(1,0,0,2), nrow = 2, ncol = 2)
> rcpp_package_function(m)
2 x 2 sparse Matrix of class "dsCMatrix"
[1,] 1 .
[2,] . 2</code></pre>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="220_dpqr_functions.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="240_na_nan_inf.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["rcpp4everyone_en.pdf", "rcpp4everyone_en.epub"],
"toc": {
"collapse": "subsection"
}
});
});
</script>
</body>
</html>