-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrd.Rmd
3439 lines (2309 loc) · 121 KB
/
rd.Rmd
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
594
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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "datadr"
subtitle: "Package Reference"
author: Ryan Hafen
copyright: Ryan Hafen
output:
packagedocs:
toc: true
rd_page: true
navpills: |
<li><a href='index.html'>Docs</a></li>
<li class="active"><a href='rd.html'>Package Ref</a></li>
<li><a href='https://github.com/delta-rho/datadr'>Github <i class='fa fa-github'></i></a></li>
brand: |-
<a href="http://deltarho.org">
<img src='figures/icon.png' alt='deltarho icon' width='30px' height='30px' style='margin-top: -3px;'>
</a>
---
<h1>Divide and Recombine for Large, Complex Data</h1>
<p><strong>Authors:</strong> <a href="mailto:[email protected]">Ryan Hafen</a> [aut, cre],Landon Sego [ctb]</p>
<p><strong>Version:</strong> 0.8.5</p>
<p><strong>License:</strong> BSD_3_clause + file LICENSE</p>
<h4>Description</h4>
<p>Methods for dividing data into subsets, applying analytical
methods to the subsets, and recombining the results. Comes with a generic
MapReduce interface as well. Works with key-value pairs stored in memory,
on local disk, or on HDFS, in the latter case using the R and Hadoop
Integrated Programming Environment (RHIPE).</p>
<h4>Depends</h4>
<p>(none)</p>
<h4>Imports</h4>
<p>
data.table (>= 1.9.6),
digest,
codetools,
hexbin,
parallel,
magrittr,
dplyr,
methods</p>
<h4>Suggests</h4>
<p>
testthat (>= 0.11.0),
roxygen2 (>= 5.0.1),
Rhipe</p>
<h4>Enhances</h4>
<p>(none)</p>
# Key-Value Pairs
## kvPair
<h3>Specify a Key-Value Pair</h3>
<p class="rd-p">Specify a key-value pair</p>
<h4>Usage</h4>
<pre class="r"><code>kvPair(k, v)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>k</dt>
<dd class="rd-dd">key - any R object</dd>
<dt>v</dt>
<dd class="rd-dd">value - any R object</dd>
</dl>
<h4>Value</h4>
<p class="rd-p"><dl>
a list of objects of class "kvPair"
</dl></p>
<h4>Examples</h4>
<pre class="r"><code>kvPair("name", "bob")</code></pre>
<h4>See also</h4>
<code><a href=#kvpairs>kvPairs</a></code>
## kvPairs
<h3>Specify a Collection of Key-Value Pairs</h3>
<p class="rd-p">Specify a collection of key-value pairs</p>
<h4>Usage</h4>
<pre class="r"><code>kvPairs(...)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>...</dt>
<dd class="rd-dd">key-value pairs (lists with two elements)</dd>
</dl>
<h4>Value</h4>
<p class="rd-p"><dl>
a list of objects of class "kvPair"
</dl></p>
<h4>Examples</h4>
<pre class="r"><code>kvPairs(kvPair(1, letters), kvPair(2, rnorm(10)))</code></pre>
<h4>See also</h4>
<code><a href=#kvpair>kvPair</a></code>
## print.kvPair
<h3>Print a key-value pair</h3>
<h4>Usage</h4>
<pre class="r"><code>printkvPair(x, ...)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>x</dt>
<dd class="rd-dd">object to be printed</dd>
<dt>...</dt>
<dd class="rd-dd">additional arguments</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code> kvPair(1, letters)</code></pre>
## print.kvValue
<h3>Print value of a key-value pair</h3>
<h4>Usage</h4>
<pre class="r"><code>printkvValue(x, ...)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>x</dt>
<dd class="rd-dd">object to be printed</dd>
<dt>...</dt>
<dd class="rd-dd">additional arguments</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code> kvPair(1, letters)</code></pre>
## kvApply
<h3>Apply Function to Key-Value Pair</h3>
<p class="rd-p">Apply a function to a single key-value pair - not a traditional R "apply" function.</p>
<h4>Usage</h4>
<pre class="r"><code>kvApply(kvPair, fn)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>kvPair</dt>
<dd class="rd-dd">a key-value pair (a list with 2 elements or object created with <code><a href=#kvpair>kvPair</a></code>)</dd>
<dt>fn</dt>
<dd class="rd-dd">a function</dd>
</dl>
<h4>Details</h4>
<p class="rd-p">Determines how a function should be applied to a key-value pair and then applies it: if the function has two formals, it applies the function giving it the key and the value as the arguments; if the function has one formal, it applies the function giving it just the value. The function is assumed to return a value unless the result is a <code><a href=#kvpair>kvPair</a></code> object. When the function returns a value the original key will be returned in the resulting key-value pair.</p>
<p class="rd-p">This provides flexibility and simplicity for when a function is only meant to be applied to the value (the most common case), but still allows keys to be used if desired.</p>
<h4>Examples</h4>
<pre class="r"><code>kv <- kvPair(1, 2)
kv
kvApply(kv, function(x) x^2)
kvApply(kv, function(k, v) v^2)
kvApply(kv, function(k, v) k + v)
kvApply(kv, function(x) kvPair("new_key", x))</code></pre>
# Distributed data objects
## ddo
<h3>Instantiate a Distributed Data Object ('ddo')</h3>
<p class="rd-p">Instantiate a distributed data object ('ddo')</p>
<h4>Usage</h4>
<pre class="r"><code>ddo(conn, update = FALSE, reset = FALSE, control = NULL, verbose = TRUE)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>conn</dt>
<dd class="rd-dd">an object pointing to where data is or will be stored for the ddf object - can be a kvConnection object created from <code><a href=#localdiskconn>localDiskConn</a></code> or <code><a href=#hdfsconn>hdfsConn</a></code>, or a data frame or list of key-value pairs</dd>
<dt>update</dt>
<dd class="rd-dd">should the attributes of this object be updated? See <code><a href=#updateattributes>updateAttributes</a></code> for more details.</dd>
<dt>reset</dt>
<dd class="rd-dd">should all persistent metadata about this object be removed and the object created from scratch? This setting does not effect data stored in the connection location.</dd>
<dt>control</dt>
<dd class="rd-dd">parameters specifying how the backend should handle things if attributes are updated (most-likely parameters to <code>rhwatch</code> in RHIPE) - see <code><a href=#rhipecontrol>rhipeControl</a></code> and <code><a href=#localdiskcontrol>localDiskControl</a></code></dd>
<dt>verbose</dt>
<dd class="rd-dd">logical - print messages about what is being done</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code>kv <- kvPairs(kvPair(1, letters), kvPair(2, rnorm(100)))
kvddo <- ddo(kv)
kvddo</code></pre>
## ddf
<h3>Instantiate a Distributed Data Frame ('ddf')</h3>
<p class="rd-p">Instantiate a distributed data frame ('ddf')</p>
<h4>Usage</h4>
<pre class="r"><code>ddf(conn, transFn = NULL, update = FALSE, reset = FALSE, control = NULL,
verbose = TRUE)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>conn</dt>
<dd class="rd-dd">an object pointing to where data is or will be stored for the ddf object - can be a kvConnection object created from <code><a href=#localdiskconn>localDiskConn</a></code> or <code><a href=#hdfsconn>hdfsConn</a></code>, or a data frame or list of key-value pairs</dd>
<dt>transFn</dt>
<dd class="rd-dd">transFn a function to be applied to the key-value pairs of this data prior to doing any processing, that transform the data into a data frame if it is not stored as such</dd>
<dt>update</dt>
<dd class="rd-dd">should the attributes of this object be updated? See <code><a href=#updateattributes>updateAttributes</a></code> for more details.</dd>
<dt>reset</dt>
<dd class="rd-dd">should all persistent metadata about this object be removed and the object created from scratch? This setting does not effect data stored in the connection location.</dd>
<dt>control</dt>
<dd class="rd-dd">parameters specifying how the backend should handle things if attributes are updated (most-likely parameters to <code>rhwatch</code> in RHIPE) - see <code><a href=#rhipecontrol>rhipeControl</a></code> and <code><a href=#localdiskcontrol>localDiskControl</a></code></dd>
<dt>verbose</dt>
<dd class="rd-dd">logical - print messages about what is being done</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code># in-memory ddf
d <- ddf(iris)
d
# local disk ddf
conn <- localDiskConn(tempfile(), autoYes = TRUE)
addData(conn, list(list("1", iris[1:10,])))
addData(conn, list(list("2", iris[11:110,])))
addData(conn, list(list("3", iris[111:150,])))
dl <- ddf(conn)
dl
# hdfs ddf (requires RHIPE / Hadoop)
# connect to empty HDFS directory
conn <- hdfsConn("/tmp/irisSplit")
# add some data
addData(conn, list(list("1", iris[1:10,])))
addData(conn, list(list("2", iris[11:110,])))
addData(conn, list(list("3", iris[111:150,])))
# represent it as a distributed data frame
hdd <- ddf(conn)</code></pre>
## updateAttributes
<h3>Update Attributes of a 'ddo' or 'ddf' Object</h3>
<p class="rd-p">Update attributes of a 'ddo' or 'ddf' object</p>
<h4>Usage</h4>
<pre class="r"><code>updateAttributes(obj, control = NULL)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>obj</dt>
<dd class="rd-dd">an object of class ddo or ddf</dd>
<dt>control</dt>
<dd class="rd-dd">parameters specifying how the backend should handle things (most-likely parameters to <code>rhwatch</code> in RHIPE) - see <code><a href=#rhipecontrol>rhipeControl</a></code></dd>
</dl>
<h4>Details</h4>
<p class="rd-p">This function looks for missing attributes related to a ddo or ddf (distributed data object or data frame) object and runs MapReduce to update them. These attributes include "splitSizeDistn", "keys", "nDiv", "nRow", and "splitRowDistn". These attributes are useful for subsequent computations that might rely on them. The result is the input modified to reflect the updated attributes, and thus it should be used as <code>obj <- updateAttributes(obj)</code>.</p>
<h4>Value</h4>
<p class="rd-p"><dl>
an object of class ddo or ddf
</dl></p>
<h4>References</h4>
<p class="rd-p">Bennett, Janine, et al. "Numerically stable, single-pass, parallel statistics algorithms. Cluster Computing and Workshops", 2009. <em>CLUSTER09. IEEE International Conference on.</em> IEEE, 2009</p>
<h4>Examples</h4>
<pre class="r"><code>d <- divide(iris, by = "Species")
# some attributes are missing:
d
summary(d)
d <- updateAttributes(d)
# now all attributes are available:
d
summary(d)</code></pre>
<h4>See also</h4>
<code><a href=#ddo>ddo</a></code>, <code><a href=#ddf>ddf</a></code>, <code><a href=#divide>divide</a></code>
<h4>Author</h4>
Ryan Hafen
## ddf-accessors
<h3>Accessor methods for 'ddf' objects</h3>
<h4>Usage</h4>
<pre class="r"><code>splitRowDistn(x)
summaryddo(object, ...)
summaryddf(object, ...)
nrow(x)
NROW(x)
ncol(x)
NCOL(x)
nrowddf(x)
NROWddf(x)
ncolddf(x)
NCOLddf(x)
namesddf(x)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>x</dt>
<dd class="rd-dd">a ddf object</dd>
<dt>object</dt>
<dd class="rd-dd">a ddf/ddo object</dd>
<dt>...</dt>
<dd class="rd-dd">additional arguments</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code>d <- divide(iris, by = "Species", update = TRUE)
nrow(d)
ncol(d)
length(d)
names(d)
summary(d)
getKeys(d)</code></pre>
## ddo-ddf-accessors
<h3>Accessor Functions</h3>
<p class="rd-p">Accessor functions for attributes of ddo/ddf objects. Methods also include <code>nrow</code> and <code>ncol</code> for ddf objects.</p>
<h4>Usage</h4>
<pre class="r"><code>kvExample(x)
bsvInfo(x)
counters(x)
splitSizeDistn(x)
getKeys(x)
hasExtractableKV(x)
lengthddo(x)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>x</dt>
<dd class="rd-dd">a ddf/ddo object</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code>d <- divide(iris, by = "Species", update = TRUE)
nrow(d)
ncol(d)
length(d)
names(d)
summary(d)
getKeys(d)</code></pre>
## ddo-ddf-attributes
<h3>Managing attributes of 'ddo' or 'ddf' objects</h3>
<p class="rd-p">These are called internally in various datadr functions. They are not meant for use outside of there, but are exported for convenience, and can be useful for better understanding ddo/ddf objects.</p>
<h4>Usage</h4>
<pre class="r"><code>setAttributes(obj, attrs)
setAttributesddf(obj, attrs)
setAttributesddo(obj, attrs)
getAttribute(obj, attrName)
getAttributes(obj, attrNames)
getAttributesddf(obj, attrNames)
getAttributesddo(obj, attrNames)
hasAttributes(obj, ...)
hasAttributesddf(obj, attrNames)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>obj</dt>
<dd class="rd-dd">ddo or ddf object</dd>
<dt>attrs</dt>
<dd class="rd-dd">a named list of attributes to set</dd>
<dt>attrName</dt>
<dd class="rd-dd">name of the attribute to get</dd>
<dt>attrNames</dt>
<dd class="rd-dd">vector of names of the attributes to get</dd>
<dt>...</dt>
<dd class="rd-dd">additional arguments</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code>d <- divide(iris, by = "Species")
getAttribute(d, "keys")</code></pre>
## print.ddo
<h3>Print a "ddo" or "ddf" Object</h3>
<p class="rd-p">Print an overview of attributes of distributed data objects (ddo) or distributed data frames (ddf)</p>
<h4>Usage</h4>
<pre class="r"><code>printddo(x, ...)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>x</dt>
<dd class="rd-dd">object to be printed</dd>
<dt>...</dt>
<dd class="rd-dd">additional arguments</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code>kv <- kvPairs(kvPair(1, letters), kvPair(2, rnorm(100)))
kvddo <- ddo(kv)
kvddo</code></pre>
<h4>Author</h4>
Ryan Hafen
# Back End Connections
## localDiskConn
<h3>Connect to Data Source on Local Disk</h3>
<p class="rd-p">Connect to a data source on local disk</p>
<h4>Usage</h4>
<pre class="r"><code>localDiskConn(loc, nBins = 0, fileHashFn = NULL, autoYes = FALSE,
reset = FALSE, verbose = TRUE)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>loc</dt>
<dd class="rd-dd">location on local disk for the data source</dd>
<dt>nBins</dt>
<dd class="rd-dd">number of bins (subdirectories) to put data files into - if anticipating a large number of k/v pairs, it is a good idea to set this to something bigger than 0</dd>
<dt>fileHashFn</dt>
<dd class="rd-dd">an optional function that operates on each key-value pair to determine the subdirectory structure for where the data should be stored for that subset, or can be specified "asis" when keys are scalar strings</dd>
<dt>autoYes</dt>
<dd class="rd-dd">automatically answer "yes" to questions about creating a path on local disk</dd>
<dt>reset</dt>
<dd class="rd-dd">should existing metadata for this object be overwritten?</dd>
<dt>verbose</dt>
<dd class="rd-dd">logical - print messages about what is being done</dd>
</dl>
<h4>Details</h4>
<p class="rd-p">This simply creates a "connection" to a directory on local disk (which need not have data in it). To actually do things with this connection, see <code><a href=#ddo>ddo</a></code>, etc. Typically, you should just use <code>loc</code> to specify where the data is or where you would like data for this connection to be stored. Metadata for the object is also stored in this directory.</p>
<h4>Value</h4>
<p class="rd-p"><dl>
a "kvConnection" object of class "localDiskConn"
</dl></p>
<h4>Examples</h4>
<pre class="r"><code># connect to empty localDisk directory
conn <- localDiskConn(file.path(tempdir(), "irisSplit"), autoYes = TRUE)
# add some data
addData(conn, list(list("1", iris[1:10,])))
addData(conn, list(list("2", iris[11:110,])))
addData(conn, list(list("3", iris[111:150,])))
# represent it as a distributed data frame
irisDdf <- ddf(conn, update = TRUE)
irisDdf</code></pre>
<h4>See also</h4>
<code><a href=#adddata>addData</a></code>, <code><a href=#ddo>ddo</a></code>, <code><a href=#ddf>ddf</a></code>, <code><a href=#localdiskconn>localDiskConn</a></code>
<h4>Author</h4>
Ryan Hafen
## digestFileHash
<h3>Digest File Hash Function</h3>
<p class="rd-p">Function to be used to specify the file where key-value pairs get stored for local disk connections, useful when keys are arbitrary objects. File names are determined using a md5 hash of the object. This is the default argument for <code>fileHashFn</code> in <code><a href='localDiskConn.html'>localDiskConn</a></code>.</p>
<h4>Usage</h4>
<pre class="r"><code>digestFileHash(keys, conn)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>keys</dt>
<dd class="rd-dd">keys to be hashed</dd>
<dt>conn</dt>
<dd class="rd-dd">a "localDiskConn" object</dd>
</dl>
<h4>Details</h4>
<p class="rd-p">You shouldnt need to call this directly other than to experiment with what the output looks like or to get ideas on how to write your own custom hash.</p>
<h4>Examples</h4>
<pre class="r"><code># connect to empty localDisk directory
path <- file.path(tempdir(), "irisSplit")
unlink(path, recursive = TRUE)
conn <- localDiskConn(path, autoYes = TRUE, fileHashFn = digestFileHash)
# add some data
addData(conn, list(list("key1", iris[1:10,])))
addData(conn, list(list("key2", iris[11:110,])))
addData(conn, list(list("key3", iris[111:150,])))
# see that files were stored by their key
list.files(path)</code></pre>
<h4>See also</h4>
<code><a href=#localdiskconn>localDiskConn</a></code>, <code><a href=#charfilehash>charFileHash</a></code>
<h4>Author</h4>
Ryan Hafen
## charFileHash
<h3>Character File Hash Function</h3>
<p class="rd-p">Function to be used to specify the file where key-value pairs get stored for local disk connections, useful when keys are scalar strings. Should be passed as the argument <code>fileHashFn</code> to <code><a href='localDiskConn.html'>localDiskConn</a></code>.</p>
<h4>Usage</h4>
<pre class="r"><code>charFileHash(keys, conn)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>keys</dt>
<dd class="rd-dd">keys to be hashed</dd>
<dt>conn</dt>
<dd class="rd-dd">a "localDiskConn" object</dd>
</dl>
<h4>Details</h4>
<p class="rd-p">You shouldnt need to call this directly other than to experiment with what the output looks like or to get ideas on how to write your own custom hash.</p>
<h4>Examples</h4>
<pre class="r"><code># connect to empty localDisk directory
path <- file.path(tempdir(), "irisSplit")
unlink(path, recursive = TRUE)
conn <- localDiskConn(path, autoYes = TRUE, fileHashFn = charFileHash)
# add some data
addData(conn, list(list("key1", iris[1:10,])))
addData(conn, list(list("key2", iris[11:110,])))
addData(conn, list(list("key3", iris[111:150,])))
# see that files were stored by their key
list.files(path)</code></pre>
<h4>See also</h4>
<code><a href=#localdiskconn>localDiskConn</a></code>, <code><a href=#digestfilehash>digestFileHash</a></code>
<h4>Author</h4>
Ryan Hafen
## localDiskControl
<h3>Specify Control Parameters for MapReduce on a Local Disk Connection</h3>
<p class="rd-p">Specify control parameters for a MapReduce on a local disk connection. Currently the parameters include:</p>
<h4>Usage</h4>
<pre class="r"><code>localDiskControl(cluster = NULL, map_buff_size_bytes = 10485760,
reduce_buff_size_bytes = 10485760, map_temp_buff_size_bytes = 10485760)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>cluster</dt>
<dd class="rd-dd">a "cluster" object obtained from <code><a href=http://www.inside-r.org/r-doc/parallel/makeCluster>makeCluster</a></code> to allow for parallel processing</dd>
<dt>map_buff_size_bytes</dt>
<dd class="rd-dd">determines how much data should be sent to each map task</dd>
<dt>reduce_buff_size_bytes</dt>
<dd class="rd-dd">determines how much data should be sent to each reduce task</dd>
<dt>map_temp_buff_size_bytes</dt>
<dd class="rd-dd">determines the size of chunks written to disk in between the map and reduce</dd>
</dl>
<h4>Note</h4>
<p class="rd-p">If you have data on a shared drive that multiple nodes can access or a high performance shared file system like Lustre, you can run a local disk MapReduce job on multiple nodes by creating a multi-node cluster with <code><a href=http://www.inside-r.org/r-doc/parallel/makeCluster>makeCluster</a></code>.</p>
<p class="rd-p">If you are using multiple cores and the input data is very small, <code>map_buff_size_bytes</code> needs to be small so that the key-value pairs will be split across cores.</p>
<h4>Examples</h4>
<pre class="r"><code># create a 2-node cluster that can be used to process in parallel
cl <- parallel::makeCluster(2)
# create a local disk control object that specifies to use this cluster
# these operations run in parallel
control <- localDiskControl(cluster = cl)
# note that setting options(defaultLocalDiskControl = control)
# will cause this to be used by default in all local disk operations
# convert in-memory ddf to local-disk ddf
ldPath <- file.path(tempdir(), "by_species")
ldConn <- localDiskConn(ldPath, autoYes = TRUE)
bySpeciesLD <- convert(divide(iris, by = "Species"), ldConn)
# update attributes using parallel cluster
updateAttributes(bySpeciesLD, control = control)
# remove temporary directories
unlink(ldPath, recursive = TRUE)
# shut down the cluster
parallel::stopCluster(cl)</code></pre>
## hdfsConn
<h3>Connect to Data Source on HDFS</h3>
<p class="rd-p">Connect to a data source on HDFS</p>
<h4>Usage</h4>
<pre class="r"><code>hdfsConn(loc, type = "sequence", autoYes = FALSE, reset = FALSE,
verbose = TRUE)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>loc</dt>
<dd class="rd-dd">location on HDFS for the data source</dd>
<dt>type</dt>
<dd class="rd-dd">the type of data ("map", "sequence", "text")</dd>
<dt>autoYes</dt>
<dd class="rd-dd">automatically answer "yes" to questions about creating a path on HDFS</dd>
<dt>reset</dt>
<dd class="rd-dd">should existing metadata for this object be overwritten?</dd>
<dt>verbose</dt>
<dd class="rd-dd">logical - print messages about what is being done</dd>
</dl>
<h4>Details</h4>
<p class="rd-p">This simply creates a "connection" to a directory on HDFS (which need not have data in it). To actually do things with this data, see <code><a href=#ddo>ddo</a></code>, etc.</p>
<h4>Value</h4>
<p class="rd-p"><dl>
a "kvConnection" object of class "hdfsConn"
</dl></p>
<h4>Examples</h4>
<pre class="r"><code> # connect to empty HDFS directory
conn <- hdfsConn("/test/irisSplit")
# add some data
addData(conn, list(list("1", iris[1:10,])))
addData(conn, list(list("2", iris[11:110,])))
addData(conn, list(list("3", iris[111:150,])))
# represent it as a distributed data frame
hdd <- ddf(conn)</code></pre>
<h4>See also</h4>
<code><a href=#adddata>addData</a></code>, <code><a href=#ddo>ddo</a></code>, <code><a href=#ddf>ddf</a></code>, <code><a href=#localdiskconn>localDiskConn</a></code>
<h4>Author</h4>
Ryan Hafen
## rhipeControl
<h3>Specify Control Parameters for RHIPE Job</h3>
<p class="rd-p">Specify control parameters for a RHIPE job. See <code>rhwatch</code> for details about each of the parameters.</p>
<h4>Usage</h4>
<pre class="r"><code>rhipeControl(mapred = NULL, setup = NULL, combiner = FALSE,
cleanup = NULL, orderby = "bytes", shared = NULL, jarfiles = NULL,
zips = NULL, jobname = "")</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>mapred, setup, combiner, cleanup, orderby, shared, jarfiles, zips, jobname</dt>
<dd class="rd-dd">arguments to <code>rhwatch</code> in RHIPE</dd>
</dl>
<h4>Examples</h4>
<pre class="r"><code># input data on HDFS
d <- ddf(hdfsConn("/path/to/big/data/on/hdfs"))
# set RHIPE / Hadoop parameters
# buffer sizes control how many k/v pairs are sent to map / reduce tasks at a time
# mapred.reduce.tasks is a Hadoop config parameter that controls # of reduce tasks
rhctl <- rhipeControl(mapred = list(
rhipe_map_buff_size = 10000,
mapred.reduce.tasks = 72,
rhipe_reduce_buff_size = 1)
# divide input data using these control parameters
divide(d, by = "var", output = hdfsConn("/path/to/output"), control = rhctl)</code></pre>
# Data I/O
## addData
<h3>Add Key-Value Pairs to a Data Connection</h3>
<p class="rd-p">Add key-value pairs to a data connection</p>
<h4>Usage</h4>
<pre class="r"><code>addData(conn, data, overwrite = FALSE)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>conn</dt>
<dd class="rd-dd">a kvConnection object</dd>
<dt>data</dt>
<dd class="rd-dd">a list of key-value pairs (list of lists where each sub-list has two elements, the key and the value)</dd>
<dt>overwrite</dt>
<dd class="rd-dd">if data with the same key is already present in the data, should it be overwritten? (does not work for HDFS connections)</dd>
</dl>
<h4>Note</h4>
<p class="rd-p">This is generally not recommended for HDFS as it writes a new file each time it is called, and can result in more individual files than Hadoop likes to deal with.</p>
<h4>Examples</h4>
<pre class="r"><code> # connect to empty HDFS directory
conn <- hdfsConn("/test/irisSplit")
# add some data
addData(conn, list(list("1", iris[1:10,])))
addData(conn, list(list("2", iris[11:110,])))
addData(conn, list(list("3", iris[111:150,])))
# represent it as a distributed data frame
hdd <- ddf(conn)</code></pre>
<h4>See also</h4>
<code><a href=#removedata>removeData</a></code>, <code><a href=#localdiskconn>localDiskConn</a></code>, <code><a href=#hdfsconn>hdfsConn</a></code>
<h4>Author</h4>
Ryan Hafen
## removeData
<h3>Remove Key-Value Pairs from a Data Connection</h3>
<p class="rd-p">Remove key-value pairs from a data connection</p>
<h4>Usage</h4>
<pre class="r"><code>removeData(conn, keys)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>conn</dt>
<dd class="rd-dd">a kvConnection object</dd>
<dt>keys</dt>
<dd class="rd-dd">a list of keys indicating which k/v pairs to remove</dd>
</dl>
<h4>Note</h4>
<p class="rd-p">This is generally not recommended for HDFS as it writes a new file each time it is called, and can result in more individual files than Hadoop likes to deal with.</p>
<h4>Examples</h4>
<pre class="r"><code># connect to empty localDisk directory
conn <- localDiskConn(file.path(tempdir(), "irisSplit"), autoYes = TRUE)
# add some data
addData(conn, list(list("1", iris[1:10,])))
addData(conn, list(list("2", iris[11:90,])))
addData(conn, list(list("3", iris[91:110,])))
addData(conn, list(list("4", iris[111:150,])))
# represent it as a distributed data frame
irisDdf <- ddf(conn, update = TRUE)
irisDdf
# remove data for keys "1" and "2"
removeData(conn, list("1", "2"))
# look at result with updated attributes (reset = TRUE removes previous attrs)
irisDdf <- ddf(conn, reset = TRUE, update = TRUE)
irisDdf</code></pre>
<h4>See also</h4>
<code><a href=#removedata>removeData</a></code>, <code><a href=#localdiskconn>localDiskConn</a></code>, <code><a href=#hdfsconn>hdfsConn</a></code>
<h4>Author</h4>
Ryan Hafen
## drRead.table
<h3>Data Input</h3>
<p class="rd-p">Reads a text file in table format and creates a distributed data frame from it, with cases corresponding to lines and variables to fields in the file.</p>
<h4>Usage</h4>
<pre class="r"><code>drReadtable(file, header = FALSE, sep = "", quote = "\"'", dec = ".",
skip = 0, fill = !blank.lines.skip, blank.lines.skip = TRUE, comment.char = "#",
allowEscapes = FALSE, encoding = "unknown", autoColClasses = TRUE,
rowsPerBlock = 50000, postTransFn = identity, output = NULL, overwrite = FALSE,
params = NULL, packages = NULL, control = NULL, ...)
drReadcsv(file, header = TRUE, sep = ",",
quote = "\"", dec = ".", fill = TRUE, comment.char = "", ...)
drReadcsv2(file, header = TRUE, sep = ";",
quote = "\"", dec = ",", fill = TRUE, comment.char = "", ...)
drReaddelim(file, header = TRUE, sep = "\t",
quote = "\"", dec = ".", fill = TRUE, comment.char = "", ...)
drReaddelim2(file, header = TRUE, sep = "\t",
quote = "\"", dec = ",", fill = TRUE, comment.char = "", ...)</code></pre>
<h4>Arguments</h4>
<dl class="rd-dl">
<dt>file</dt>
<dd class="rd-dd">input text file - can either be character string pointing to a file on local disk, or an <code><a href=#hdfsconn>hdfsConn</a></code> object pointing to a text file on HDFS (see <code>output</code> argument below)</dd>
<dt>header</dt>
<dd class="rd-dd">this and parameters other parameters below are passed to <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for each chunk being processed - see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info. Most all have defaults or appropriate defaults are set through other format-specific functions such as <code>drRead.csv</code> and <code>drRead.delim</code>.</dd>
<dt>sep</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>quote</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>dec</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>skip</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>fill</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>blank.lines.skip</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>comment.char</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>allowEscapes</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>encoding</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
<dt>autoColClasses</dt>
<dd class="rd-dd">should column classes be determined automatically by reading in a sample? This can sometimes be problematic because of strange ways R handles quotes in <code>read.table</code>, but keeping the default of <code>TRUE</code> is advantageous for speed.</dd>
<dt>rowsPerBlock</dt>
<dd class="rd-dd">how many rows of the input file should make up a block (key-value pair) of output?</dd>
<dt>postTransFn</dt>
<dd class="rd-dd">a function to be applied after a block is read in to provide any additional processingn before the block is stored</dd>
<dt>output</dt>
<dd class="rd-dd">a "kvConnection" object indicating where the output data should reside. Must be a <code><a href=#localdiskconn>localDiskConn</a></code> object if input is a text file on local disk, or a <code><a href=#hdfsconn>hdfsConn</a></code> object if input is a text file on HDFS.</dd>
<dt>overwrite</dt>
<dd class="rd-dd">logical; should existing output location be overwritten? (also can specify <code>overwrite = "backup"</code> to move the existing output to _bak)</dd>
<dt>params</dt>
<dd class="rd-dd">a named list of objects external to the input data that are needed in <code>postTransFn</code></dd>
<dt>packages</dt>
<dd class="rd-dd">a vector of R package names that contain functions used in <code>fn</code> (most should be taken care of automatically such that this is rarely necessary to specify)</dd>
<dt>control</dt>
<dd class="rd-dd">parameters specifying how the backend should handle things (most-likely parameters to <code>rhwatch</code> in RHIPE) - see <code><a href=#rhipecontrol>rhipeControl</a></code> and <code><a href=#localdiskcontrol>localDiskControl</a></code></dd>
<dt>...</dt>
<dd class="rd-dd">see <code><a href=http://www.inside-r.org/r-doc/utils/read.table>read.table</a></code> for more info</dd>
</dl>
<h4>Value</h4>
<p class="rd-p"><dl>
an object of class "ddf"
</dl></p>
<h4>Note</h4>
<p class="rd-p">For local disk, the file is actually read in sequentially instead of in parallel. This is because of possible performance issues when trying to read from the same disk in parallel.</p>
<p class="rd-p">Note that if <code>skip</code> is positive and/or if <code>header</code> is <code>TRUE</code>, it will first read these in as they only occur once in the data, and we then check for these lines in each block and remove those lines if they appear.</p>