-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-97-metadata.html
1372 lines (1234 loc) · 67.3 KB
/
import-97-metadata.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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
window.onload = function() {
var imgs = document.getElementsByTagName('img'), i, img;
for (i = 0; i < imgs.length; i++) {
img = imgs[i];
// center an image if it is the only element of its parent
if (img.parentElement.childElementCount === 1)
img.parentElement.style.textAlign = 'center';
}
};
</script>
<!-- Styles for R syntax highlighter -->
<style type="text/css">
pre .operator,
pre .paren {
color: rgb(104, 118, 135)
}
pre .literal {
color: #990073
}
pre .number {
color: #099;
}
pre .comment {
color: #998;
font-style: italic
}
pre .keyword {
color: #900;
font-weight: bold
}
pre .identifier {
color: rgb(0, 0, 0);
}
pre .string {
color: #d14;
}
</style>
<!-- R syntax highlighter -->
<script type="text/javascript">
var hljs=new function(){function m(p){return p.replace(/&/gm,"&").replace(/</gm,"<")}function f(r,q,p){return RegExp(q,"m"+(r.cI?"i":"")+(p?"g":""))}function b(r){for(var p=0;p<r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName=="CODE"){return q}if(!(q.nodeType==3&&q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p="";for(var r=0;r<t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,"")}p+=q}else{if(t.childNodes[r].nodeName=="BR"){p+="\n"}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,"\n")}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q<r.length;q++){var p=r[q].replace(/^language-/,"");if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r<s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName=="BR"){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:"start",offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:"stop",offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z="";var s=[];function u(){if(y.length&&w.length){if(y[0].offset!=w[0].offset){return(y[0].offset<w[0].offset)?y:w}else{return w[0].event=="start"?y:w}}else{return y.length?y:w}}function t(D){var A="<"+D.nodeName.toLowerCase();for(var B=0;B<D.attributes.length;B++){var C=D.attributes[B];A+=" "+C.nodeName.toLowerCase();if(C.value!==undefined&&C.value!==false&&C.value!==null){A+='="'+m(C.value)+'"'}}return A+">"}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event=="start"){z+=t(v.node);s.push(v.node)}else{if(v.event=="stop"){var p,r=s.length;do{r--;p=s[r];z+=("</"+p.nodeName.toLowerCase()+">")}while(p!=v.node);s.splice(r,1);while(r<s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w="keyword"}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b="\\b("+s.join("|")+")\\s"}x.bR=f(y,x.b?x.b:"\\B|\\b");if(!x.e&&!x.eW){x.e="\\B|\\b"}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t<x.c.length;t++){if(x.c[t]=="self"){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L<M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&&D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&&L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L<N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join("|"),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),"",true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&&M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r="";var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+='<span class="'+N[0]+'">'+M[0]+"</span>"}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&&e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?'<span class="'+M.cN+'">':"";if(M.rB){y+=L;M.buffer=""}else{if(M.eB){y+=m(r)+L;M.buffer=""}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?"</span>":"";if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L>1){O=D[D.length-2].cN?"</span>":"";y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer="";if(r.starts){I(r.starts,"")}return R.rE}if(w(M,R)){throw"Illegal"}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y="";try{var s,u=0;E.dM.buffer="";do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length>1){throw"Illegal"}return{r:A,keyword_count:x,value:y}}catch(H){if(H=="Illegal"){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r>r.keyword_count+r.r){r=s}if(s.keyword_count+s.r>p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((<[^>]+>|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,"<br>")}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement("pre");s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match("(\\s|^)(language-)?"+v+"(\\s|$)")){u=u?(u+" "+v):v}if(/MSIE [678]/.test(navigator.userAgent)&&t.tagName=="CODE"&&t.parentNode.tagName=="PRE"){s=t.parentNode;var p=document.createElement("div");p.innerHTML="<pre><code>"+y.value+"</code></pre>";t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName("pre");for(var p=0;p<r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener("DOMContentLoaded",o,false);window.addEventListener("load",o,false)}else{if(window.attachEvent){window.attachEvent("onload",o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.ER="(?![\\s\\S])";this.BE={b:"\\\\.",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE],r:0};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{"false":1,"int":1,"float":1,"while":1,"private":1,"char":1,"catch":1,"export":1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,"const":1,struct:1,"for":1,static_cast:2,union:1,namespace:1,unsigned:1,"long":1,"throw":1,"volatile":2,"static":1,"protected":1,bool:1,template:1,mutable:1,"if":1,"public":1,friend:2,"do":1,"return":1,"goto":1,auto:1,"void":2,"enum":1,"else":1,"break":1,"new":1,extern:1,using:1,"true":1,"class":1,asm:1,"case":1,typeid:1,"short":1,reinterpret_cast:2,"default":1,"double":1,register:1,explicit:1,signed:1,typename:1,"try":1,"this":1,"switch":1,"continue":1,wchar_t:1,inline:1,"delete":1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:"</",c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:"string",b:"'\\\\?.",e:"'",i:"."},{cN:"number",b:"\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)"},hljs.CNM,{cN:"preprocessor",b:"#",e:"$"},{cN:"stl_container",b:"\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<",e:">",k:a,r:10,c:["self"]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:"number",b:"\\b0[xX][0-9a-fA-F]+[Li]?\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\b\\d+\\.(?!\\d)(?:i\\b)?",e:hljs.IMMEDIATE_RE,r:1},{cN:"number",b:"\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"keyword",b:"(?:tryCatch|library|setGeneric|setGroupGeneric)\\b",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\.\\.\\.",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\.\\.\\d+(?![\\w.])",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\b(?:function)",e:hljs.IMMEDIATE_RE,r:2},{cN:"keyword",b:"(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"literal",b:"(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b",e:hljs.IMMEDIATE_RE,r:10},{cN:"literal",b:"(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"identifier",b:"[a-zA-Z.][a-zA-Z0-9._]*\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"operator",b:"<\\-(?!\\s*\\d)",e:hljs.IMMEDIATE_RE,r:2},{cN:"operator",b:"\\->|<\\-",e:hljs.IMMEDIATE_RE,r:1},{cN:"operator",b:"%%|~",e:hljs.IMMEDIATE_RE},{cN:"operator",b:">=|<=|==|!=|\\|\\||&&|=|\\+|\\-|\\*|/|\\^|>|<|!|&|\\||\\$|:",e:hljs.IMMEDIATE_RE,r:0},{cN:"operator",b:"%",e:"%",i:"\\n",r:1},{cN:"identifier",b:"`",e:"`",r:0},{cN:"string",b:'"',e:'"',c:[hljs.BE],r:0},{cN:"string",b:"'",e:"'",c:[hljs.BE],r:0},{cN:"paren",b:"[[({\\])}]",e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
</script>
<style type="text/css">
body, td {
font-family: sans-serif;
background-color: white;
font-size: 13px;
}
body {
max-width: 800px;
margin: auto;
padding: 1em;
line-height: 20px;
}
tt, code, pre {
font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace;
}
h1 {
font-size:2.2em;
}
h2 {
font-size:1.8em;
}
h3 {
font-size:1.4em;
}
h4 {
font-size:1.0em;
}
h5 {
font-size:0.9em;
}
h6 {
font-size:0.8em;
}
a:visited {
color: rgb(50%, 0%, 50%);
}
pre, img {
max-width: 100%;
}
pre {
overflow-x: auto;
}
pre code {
display: block; padding: 0.5em;
}
code {
font-size: 92%;
border: 1px solid #ccc;
}
code[class] {
background-color: #F8F8F8;
}
table, td, th {
border: none;
}
blockquote {
color:#666666;
margin:0;
padding-left: 1em;
border-left: 0.5em #EEE solid;
}
hr {
height: 0px;
border-bottom: none;
border-top-width: thin;
border-top-style: dotted;
border-top-color: #999999;
}
@media print {
* {
background: transparent !important;
color: black !important;
filter:none !important;
-ms-filter: none !important;
}
body {
font-size:12pt;
max-width:100%;
}
a, a:visited {
text-decoration: underline;
}
hr {
visibility: hidden;
page-break-before: always;
}
pre, blockquote {
padding-right: 1em;
page-break-inside: avoid;
}
tr, img {
page-break-inside: avoid;
}
img {
max-width: 100% !important;
}
@page :left {
margin: 15mm 20mm 15mm 10mm;
}
@page :right {
margin: 15mm 10mm 15mm 20mm;
}
p, h2, h3 {
orphans: 3; widows: 3;
}
h2, h3 {
page-break-after: avoid;
}
}
</style>
</head>
<body>
<p>This report was automatically generated with the R package <strong>knitr</strong>
(version 1.20).</p>
<pre><code class="r"># knitr::stitch_rmd(script="./dal/import-79-metadata.R", output="./stitched-output/dal/import-metadata.md") # dir.create(output="./stitched-output/dal/", recursive=T)
rm(list=ls(all=TRUE)) #Clear the variables from previous runs.
</code></pre>
<pre><code class="r"># Call `base::source()` on any repo file that defines functions needed below. Ideally, no real operations are performed.
base::source("utility/connectivity.R")
</code></pre>
<pre><code class="r"># Attach these package(s) so their functions don't need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path
library(magrittr , quietly=TRUE)
# Verify these packages are available on the machine, but their functions need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path
requireNamespace("readr" )
requireNamespace("tidyr" )
requireNamespace("tibble" )
requireNamespace("purrr" )
requireNamespace("dplyr" ) #Avoid attaching dplyr, b/c its function names conflict with a lot of packages (esp base, stats, and plyr).
requireNamespace("testit" ) #For asserting conditions meet expected patterns.
requireNamespace("odbc" ) #For communicating with SQL Server over a locally-configured DSN. Uncomment if you use 'upload-to-db' chunk.
</code></pre>
<pre><code class="r"># Constant values that won't change.
config <- config::get()
directory_in <- "data-public/metadata/tables-97"
study <- "97"
shallow_only <- F # If TRUE, update only the metadata tables that won't delete any other database tables.
col_types_minimal <- readr::cols_only(
ID = readr::col_integer(),
Label = readr::col_character(),
Active = readr::col_logical(),
Notes = readr::col_character()
)
# The order of this list matters.
# - Tables are WRITTEN from top to bottom.
# - Tables are DELETED from bottom to top.
lst_col_types <- list(
ArchiveDescription = readr::cols_only(
AlgorithmVersion = readr::col_integer(),
Description = readr::col_character(),
Date = readr::col_date()
),
item = readr::cols_only(
ID = readr::col_integer(),
Label = readr::col_character(),
MinValue = readr::col_integer(),
MinNonnegative = readr::col_integer(),
MaxValue = readr::col_integer(),
Active = readr::col_logical(),
Notes = readr::col_character()
),
LUExtractSource = col_types_minimal,
LUMarkerEvidence = col_types_minimal,
LUGender = col_types_minimal,
LUMarkerType = readr::cols_only(
ID = readr::col_integer(),
Label = readr::col_character(),
Explicit = readr::col_integer(),
Active = readr::col_logical(),
Notes = readr::col_character()
),
LUMultipleBirth = col_types_minimal,
LURaceCohort = col_types_minimal,
LURoster = col_types_minimal,
LUTristate = col_types_minimal,
LUYesNo = col_types_minimal,
MzManual = readr::cols_only(
ID = readr::col_integer(),
SubjectTag_S1 = readr::col_integer(),
SubjectTag_S2 = readr::col_integer(),
MultipleBirthIfSameSex = readr::col_integer(),
IsMz = readr::col_integer(),
Undecided = readr::col_integer(),
Related = readr::col_integer(),
Notes = readr::col_character()
),
RosterAssignment = readr::cols_only(
ID = readr::col_integer(),
ResponseLower = readr::col_integer(),
ResponseUpper = readr::col_integer(),
Freq = readr::col_integer(),
Resolved = readr::col_integer(),
R = readr::col_double(),
RBoundLower = readr::col_double(),
RBoundUpper = readr::col_double(),
SameGeneration = readr::col_double(),
ShareBiodad = readr::col_integer(),
ShareBiomom = readr::col_integer(),
ShareBiograndparent = readr::col_integer(),
Inconsistent = readr::col_integer(),
Notes = readr::col_character(),
ResponseLowerLabel = readr::col_character(),
ResponseUpperLabel = readr::col_character()
),
variable = readr::cols_only(
# ID = readr::col_integer(),
VariableCode = readr::col_character(),
Item = readr::col_integer(),
ExtractSource = readr::col_integer(),
SurveyYear = readr::col_integer(),
LoopIndex1 = readr::col_integer(),
LoopIndex2 = readr::col_integer(),
Translate = readr::col_integer(),
Active = readr::col_integer(),
Notes = readr::col_character(),
QuestionName = readr::col_character(),
VariableTitle = readr::col_character()
)
)
col_types_mapping <- readr::cols_only(
table_name = readr::col_character(),
schema_name = readr::col_character(),
enum_name = readr::col_character(),
# enum_file = readr::col_character(),
c_sharp_type = readr::col_character(),
convert_to_enum = readr::col_logical(),
shallow = readr::col_logical()
)
ds_file <- lst_col_types %>%
tibble::enframe(value = "col_types") %>%
dplyr::mutate(
path = file.path(directory_in, paste0(name, ".csv")),
exists = purrr::map_lgl(path, file.exists)
# col_types = purrr::map(name, function(x) lst_col_types[[x]]),
) %>%
dplyr::select(name, path, dplyr::everything())
ds_file
</code></pre>
<pre><code>## # A tibble: 14 x 4
## name path col_types exists
## <chr> <chr> <list> <lgl>
## 1 ArchiveDescription data-public/metadata/tables-97/A~ <S3: col_s~ TRUE
## 2 item data-public/metadata/tables-97/i~ <S3: col_s~ TRUE
## 3 LUExtractSource data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 4 LUMarkerEvidence data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 5 LUGender data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 6 LUMarkerType data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 7 LUMultipleBirth data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 8 LURaceCohort data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 9 LURoster data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 10 LUTristate data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 11 LUYesNo data-public/metadata/tables-97/L~ <S3: col_s~ TRUE
## 12 MzManual data-public/metadata/tables-97/M~ <S3: col_s~ TRUE
## 13 RosterAssignment data-public/metadata/tables-97/R~ <S3: col_s~ TRUE
## 14 variable data-public/metadata/tables-97/v~ <S3: col_s~ TRUE
</code></pre>
<pre><code class="r">start_time <- Sys.time()
ds_mapping <- readr::read_csv(file.path(directory_in, "_mapping.csv"), col_types=col_types_mapping)
testit::assert("All metadata files must exist.", all(ds_file$exists))
ds_entries <- ds_file %>%
# dplyr::slice(14) %>%
dplyr::select(name, path, col_types) %>%
dplyr::mutate(
entries = purrr::pmap(list(file=.$path, col_types=.$col_types), readr::read_csv, comment = "#")
)
ds_entries
</code></pre>
<pre><code>## # A tibble: 14 x 4
## name path col_types entries
## <chr> <chr> <list> <list>
## 1 ArchiveDescription data-public/metadata/table~ <S3: col_s~ <tibble [8 ~
## 2 item data-public/metadata/table~ <S3: col_s~ <tibble [26~
## 3 LUExtractSource data-public/metadata/table~ <S3: col_s~ <tibble [6 ~
## 4 LUMarkerEvidence data-public/metadata/table~ <S3: col_s~ <tibble [8 ~
## 5 LUGender data-public/metadata/table~ <S3: col_s~ <tibble [3 ~
## 6 LUMarkerType data-public/metadata/table~ <S3: col_s~ <tibble [28~
## 7 LUMultipleBirth data-public/metadata/table~ <S3: col_s~ <tibble [5 ~
## 8 LURaceCohort data-public/metadata/table~ <S3: col_s~ <tibble [4 ~
## 9 LURoster data-public/metadata/table~ <S3: col_s~ <tibble [92~
## 10 LUTristate data-public/metadata/table~ <S3: col_s~ <tibble [3 ~
## 11 LUYesNo data-public/metadata/table~ <S3: col_s~ <tibble [6 ~
## 12 MzManual data-public/metadata/table~ <S3: col_s~ <tibble [90~
## 13 RosterAssignment data-public/metadata/table~ <S3: col_s~ <tibble [31~
## 14 variable data-public/metadata/table~ <S3: col_s~ <tibble [55~
</code></pre>
<pre><code class="r"># d <- readr::read_csv("data-public/metadata/tables/variable_97.csv", col_types=lst_col_types$variable_97, comment = "#")
# readr::problems(d)
# ds_entries$entries[15]
ds_table <- database_inventory(study)
ds_table
</code></pre>
<pre><code>## # A tibble: 32 x 6
## schema_name table_name row_count column_count space_total_kb
## * <chr> <chr> <int> <int> <int>
## 1 Archive tblArchiveDescription 8 3 72
## 2 Archive tblRelatedValuesArch~ 27709 23 2392
## 3 dbo sysdiagrams 0 5 0
## 4 Enum tblLUExtractSource 6 4 72
## 5 Enum tblLUGender 3 4 72
## 6 Enum tblLUMarkerEvidence 8 4 72
## 7 Enum tblLUMarkerType 28 5 72
## 8 Enum tblLUMultipleBirth 5 4 72
## 9 Enum tblLURaceCohort 4 4 72
## 10 Enum tblLURoster 92 4 72
## # ... with 22 more rows, and 1 more variable: space_used_kb <int>
</code></pre>
<pre><code class="r">rm(directory_in) # rm(col_types_tulsa)
</code></pre>
<pre><code class="r"># OuhscMunge::column_rename_headstart(ds_county) #Spit out columns to help write call to `dplyr::rename()`.
if( shallow_only ) {
ds_mapping <- ds_mapping %>%
dplyr::filter(.data$shallow)
}
ds_mapping
</code></pre>
<pre><code>## # A tibble: 14 x 6
## table_name schema_name enum_name c_sharp_type convert_to_enum shallow
## <chr> <chr> <chr> <chr> <lgl> <lgl>
## 1 ArchiveDesc~ Archive NA_chara~ NA_character FALSE TRUE
## 2 item Metadata Item short TRUE FALSE
## 3 LUExtractSo~ Enum ExtractS~ byte TRUE FALSE
## 4 LUGender Enum Gender byte TRUE FALSE
## 5 LUMarkerEvi~ Enum MarkerEv~ byte TRUE FALSE
## 6 LUMarkerType Enum MarkerTy~ byte TRUE FALSE
## 7 LUMultipleB~ Enum Multiple~ byte TRUE FALSE
## 8 LURaceCohort Enum RaceCoho~ byte TRUE FALSE
## 9 LURoster Enum RosterGe~ short TRUE FALSE
## 10 LUTristate Enum Tristate byte TRUE FALSE
## 11 LUYesNo Enum YesNo short TRUE FALSE
## 12 MzManual Metadata NA_chara~ NA_character FALSE TRUE
## 13 RosterAssig~ Metadata NA_chara~ NA_character FALSE FALSE
## 14 variable Metadata NA_chara~ NA_character FALSE FALSE
</code></pre>
<pre><code class="r">ds_file <- ds_file %>%
dplyr::inner_join(ds_mapping, by=c("name"="table_name")) %>%
dplyr::mutate(
table_name = paste0("tbl", name),
sql_delete = glue::glue("DELETE FROM {schema_name}.{table_name};")
) %>%
dplyr::left_join(
ds_entries %>%
dplyr::select(name, entries)
, by="name"
)
rm(ds_entries)
ds_file$entries %>%
purrr::walk(print)
</code></pre>
<pre><code>## # A tibble: 8 x 3
## AlgorithmVersion Description Date
## <int> <chr> <date>
## 1 1 naive roster 2018-01-17
## 2 2 account for twins 2018-01-18
## 3 3 same sib full twins are R=.5 by default, an~ 2018-02-14
## 4 7 allows nulls for RFull 2018-06-19
## 5 8 recover different-sex full sibs 2018-06-19
## 6 9 recover same-sex full sibs 2018-06-19
## 7 10 allow nonsibs to still be r>0 2018-06-19
## 8 11 refresh 2018-06-20
## # A tibble: 26 x 7
## ID Label MinValue MinNonnegative MaxValue Active Notes
## <int> <chr> <int> <int> <int> <lgl> <chr>
## 1 1 subject_id 1 1 9022 TRUE <NA>
## 2 2 extended_famil~ 1 1 9022 TRUE <NA>
## 3 3 hh_internal_id 1 1 5 TRUE <NA>
## 4 10 gender 1 1 2 TRUE <NA>
## 5 11 DateOfBirthMon~ 1 1 12 TRUE <NA>
## 6 12 DateOfBirthYear 1980 1980 1984 TRUE <NA>
## 7 13 cross_sectiona~ 0 0 1 TRUE <NA>
## 8 14 race_cohort 1 1 4 TRUE race-eth~
## 9 20 InterviewDateD~ -7 1 31 TRUE <NA>
## 10 21 InterviewDateM~ -7 1 12 TRUE <NA>
## # ... with 16 more rows
## # A tibble: 6 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 1 97-demographics TRUE <NA>
## 2 2 97-roster TRUE <NA>
## 3 3 97-survey-time TRUE <NA>
## 4 4 97-links-explicit TRUE <NA>
## 5 5 97-links-implicit TRUE <NA>
## 6 6 97-twins TRUE <NA>
## # A tibble: 8 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 0 Irrelevant TRUE <NA>
## 2 1 StronglySupports TRUE <NA>
## 3 2 Supports TRUE <NA>
## 4 3 Consistent TRUE <NA>
## 5 4 Ambiguous TRUE <NA>
## 6 5 Missing TRUE <NA>
## 7 6 Unlikely TRUE <NA>
## 8 7 Disconfirms TRUE <NA>
## # A tibble: 3 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 1 Male TRUE <NA>
## 2 2 Female TRUE <NA>
## 3 255 InvalidSkipGen2 TRUE <NA>
## # A tibble: 28 x 5
## ID Label Explicit Active Notes
## <int> <chr> <int> <lgl> <chr>
## 1 1 Roster 1 TRUE <NA>
## 2 2 ShareBiomom 1 TRUE <NA>
## 3 3 ShareBiodad 1 TRUE <NA>
## 4 5 DobSeparation 0 FALSE <NA>
## 5 6 GenderAgreement 0 FALSE <NA>
## 6 10 FatherAsthma 0 FALSE <NA>
## 7 11 BabyDaddyAsthma 0 FALSE <NA>
## 8 12 BabyDaddyLeftHHDate 0 FALSE <NA>
## 9 13 BabyDaddyDeathDate 0 FALSE <NA>
## 10 14 BabyDaddyAlive 0 FALSE <NA>
## # ... with 18 more rows
## # A tibble: 5 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 0 No TRUE <NA>
## 2 2 Twin TRUE <NA>
## 3 3 Trip TRUE <NA>
## 4 4 TwinOrTrip FALSE Currently Then Gen1 algorithm doesn't distingui~
## 5 255 DoNotKnow TRUE <NA>
## # A tibble: 4 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 1 Black TRUE <NA>
## 2 2 Hispanic TRUE <NA>
## 3 3 Mixed TRUE <NA>
## 4 4 Nbnh TRUE <NA>
## # A tibble: 92 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 -4 valid_skip TRUE <NA>
## 2 -2 do_not_know TRUE <NA>
## 3 -1 refusal TRUE <NA>
## 4 0 self TRUE <NA>
## 5 1 wife TRUE <NA>
## 6 2 husband TRUE <NA>
## 7 3 mother TRUE <NA>
## 8 4 father TRUE <NA>
## 9 7 mother_step TRUE <NA>
## 10 8 father_step TRUE <NA>
## # ... with 82 more rows
## # A tibble: 3 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 0 No TRUE <NA>
## 2 1 Yes TRUE <NA>
## 3 255 DoNotKnow TRUE <NA>
## # A tibble: 6 x 4
## ID Label Active Notes
## <int> <chr> <lgl> <chr>
## 1 -6 ValidSkipOrNoInterviewOrNotInSurvey TRUE <NA>
## 2 -3 InvalidSkip TRUE <NA>
## 3 -2 DoNotKnow TRUE <NA>
## 4 -1 Refusal TRUE <NA>
## 5 0 No TRUE <NA>
## 6 1 Yes TRUE <NA>
## # A tibble: 90 x 8
## ID SubjectTag_S1 SubjectTag_S2 MultipleBirthIfSameS~ IsMz Undecided
## <int> <int> <int> <int> <int> <int>
## 1 1 66 67 0 0 0
## 2 2 75 76 2 1 0
## 3 3 116 117 2 1 0
## 4 4 222 223 2 0 0
## 5 5 343 344 3 255 1
## 6 6 343 345 3 255 1
## 7 7 344 345 3 255 1
## 8 8 351 352 2 1 0
## 9 9 447 448 2 1 0
## 10 10 588 589 2 0 0
## # ... with 80 more rows, and 2 more variables: Related <int>, Notes <chr>
## # A tibble: 31 x 16
## ID ResponseLower ResponseUpper Freq Resolved R RBoundLower
## <int> <int> <int> <int> <int> <dbl> <dbl>
## 1 1 -2 -1 2 0 NA 0
## 2 2 -1 -1 2 0 NA 0
## 3 3 13 13 1034 0 0.5 0.5
## 4 4 13 14 2034 1 0.5 0.5
## 5 5 14 14 1154 0 0.5 0.5
## 6 6 15 15 48 1 0.25 0.25
## 7 7 15 18 132 1 0.25 0.25
## 8 8 16 19 2 1 0.25 0.25
## 9 9 18 18 62 1 0.25 0.25
## 10 10 19 19 8 1 0.25 0.25
## # ... with 21 more rows, and 9 more variables: RBoundUpper <dbl>,
## # SameGeneration <dbl>, ShareBiodad <int>, ShareBiomom <int>,
## # ShareBiograndparent <int>, Inconsistent <int>, Notes <chr>,
## # ResponseLowerLabel <chr>, ResponseUpperLabel <chr>
## # A tibble: 551 x 11
## VariableCode Item ExtractSource SurveyYear LoopIndex1 LoopIndex2
## <chr> <int> <int> <int> <int> <int>
## 1 R0000100 1 1 1997 1 1
## 2 R1193000 2 1 1997 1 1
## 3 R0533400 3 1 1997 1 1
## 4 R0536300 10 1 1997 1 1
## 5 R0536401 11 1 1997 1 1
## 6 R0536402 12 1 1997 1 1
## 7 R1235800 13 1 1997 1 1
## 8 R1482600 14 1 1997 1 1
## 9 R1097800 101 2 1997 1 1
## 10 R1097900 101 2 1997 2 1
## # ... with 541 more rows, and 5 more variables: Translate <int>,
## # Active <int>, Notes <chr>, QuestionName <chr>, VariableTitle <chr>
</code></pre>
<pre><code class="r"># ds_file %>%
# dplyr::group_by(name) %>%
# dplyr::mutate(
# a = purrr::map_int(entries, ~max(nchar(.), na.rm=T))
# ) %>%
# dplyr::ungroup() %>%
# dplyr::pull(a)
# ds_file %>%
# dplyr::select(name, entries) %>%
# tibble::deframe() %>%
# purrr::map(~max(nchar(.), na.rm=T))
# lst_ds %>%
# purrr::map(nrow)
# lst_ds %>%
# purrr::map(readr::spec)
ds_file$table_name
</code></pre>
<pre><code>## [1] "tblArchiveDescription" "tblitem"
## [3] "tblLUExtractSource" "tblLUMarkerEvidence"
## [5] "tblLUGender" "tblLUMarkerType"
## [7] "tblLUMultipleBirth" "tblLURaceCohort"
## [9] "tblLURoster" "tblLUTristate"
## [11] "tblLUYesNo" "tblMzManual"
## [13] "tblRosterAssignment" "tblvariable"
</code></pre>
<pre><code class="r">ds_file
</code></pre>
<pre><code>## # A tibble: 14 x 12
## name path col_types exists schema_name enum_name c_sharp_type
## <chr> <chr> <list> <lgl> <chr> <chr> <chr>
## 1 Archiv~ data-publi~ <S3: col~ TRUE Archive NA_chara~ NA_character
## 2 item data-publi~ <S3: col~ TRUE Metadata Item short
## 3 LUExtr~ data-publi~ <S3: col~ TRUE Enum ExtractS~ byte
## 4 LUMark~ data-publi~ <S3: col~ TRUE Enum MarkerEv~ byte
## 5 LUGend~ data-publi~ <S3: col~ TRUE Enum Gender byte
## 6 LUMark~ data-publi~ <S3: col~ TRUE Enum MarkerTy~ byte
## 7 LUMult~ data-publi~ <S3: col~ TRUE Enum Multiple~ byte
## 8 LURace~ data-publi~ <S3: col~ TRUE Enum RaceCoho~ byte
## 9 LURost~ data-publi~ <S3: col~ TRUE Enum RosterGe~ short
## 10 LUTris~ data-publi~ <S3: col~ TRUE Enum Tristate byte
## 11 LUYesNo data-publi~ <S3: col~ TRUE Enum YesNo short
## 12 MzManu~ data-publi~ <S3: col~ TRUE Metadata NA_chara~ NA_character
## 13 Roster~ data-publi~ <S3: col~ TRUE Metadata NA_chara~ NA_character
## 14 variab~ data-publi~ <S3: col~ TRUE Metadata NA_chara~ NA_character
## # ... with 5 more variables: convert_to_enum <lgl>, shallow <lgl>,
## # table_name <chr>, sql_delete <chr>, entries <list>
</code></pre>
<pre><code class="r">create_enum_body <- function( d ) {
tab_spaces <- " "
labels <- dplyr::if_else( d$Active , d$Label, paste("//", d$Label))
comments <- dplyr::if_else(is.na(d$Notes ), "" , paste("//", d$Notes))
paste0(sprintf("%s%-60s = %5s, %s\n", tab_spaces, labels, d$ID, comments), collapse="")
}
# ds_file %>%
# dplyr::filter(name=="LURelationshipPath") %>%
# dplyr::pull(entries)
ds_enum <- ds_file %>%
dplyr::filter(convert_to_enum) %>%
dplyr::select(enum_name, entries, c_sharp_type) %>%
dplyr::mutate(
enum_header = paste0("\npublic enum ", .$enum_name, " {\n"),
enum_body = purrr::map_chr(.$entries, create_enum_body),
enum_footer = "}\n",
enum_cs = paste0(enum_header, enum_body, enum_footer)
) %>%
dplyr::select(-enum_header, -enum_body, -enum_footer)
ds_enum %>%
dplyr::pull(enum_cs) %>%
cat()
</code></pre>
<pre><code>##
## public enum Item {
## subject_id = 1,
## extended_family_id = 2,
## hh_internal_id = 3,
## gender = 10,
## DateOfBirthMonth = 11,
## DateOfBirthYear = 12,
## cross_sectional_cohort = 13,
## race_cohort = 14, // race-ethnicity
## InterviewDateDay = 20,
## InterviewDateMonth = 21,
## InterviewDateYear = 22,
## AgeAtInterviewDateMonths = 23,
## AgeAtInterviewDateYears = 24,
## roster_crosswalk = 101,
## hh_member_id = 102,
## hh_informant = 103,
## // roster_relationship_2_dim = 104, // 16 x 16 square
## roster_relationship_1_dim = 105, // 1 x 16 vector
## hh_unique_id = 106, // HHI2: People living in the Household - sorted, UID; HH member's unique ID
## pair_multiple_birth = 121,
## pair_twins_mz = 122,
## pair_sister_same_bioparent = 123,
## pair_brother_same_bioparent = 124,
## // InterviewDateDayParent_NOTUSED = 1020,
## // InterviewDateMonthParent_NOTUSED = 1021,
## // InterviewDateYearParent_NOTUSED = 1022,
## }
##
## public enum ExtractSource {
## 97-demographics = 1,
## 97-roster = 2,
## 97-survey-time = 3,
## 97-links-explicit = 4,
## 97-links-implicit = 5,
## 97-twins = 6,
## }
##
## public enum MarkerEvidence {
## Irrelevant = 0,
## StronglySupports = 1,
## Supports = 2,
## Consistent = 3,
## Ambiguous = 4,
## Missing = 5,
## Unlikely = 6,
## Disconfirms = 7,
## }
##
## public enum Gender {
## Male = 1,
## Female = 2,
## InvalidSkipGen2 = 255,
## }
##
## public enum MarkerType {
## Roster = 1,
## ShareBiomom = 2,
## ShareBiodad = 3,
## // DobSeparation = 5,
## // GenderAgreement = 6,
## // FatherAsthma = 10,
## // BabyDaddyAsthma = 11,
## // BabyDaddyLeftHHDate = 12,
## // BabyDaddyDeathDate = 13,
## // BabyDaddyAlive = 14,
## // BabyDaddyInHH = 15,
## // BabyDaddyDistanceFromHH = 16,
## // Gen2CFatherAlive = 17,
## // Gen2CFatherInHH = 18,
## // Gen2CFatherDistanceFromHH = 19,
## // Gen1BiodadInHH = 30,
## // Gen1BiodadDeathAge = 31,
## // Gen1BiodadBirthYear = 32,
## // Gen1BiodadInHH1979 = 33,
## // Gen1BiodadBirthCountry = 34,
## // Gen1BiodadBirthState = 35,
## // Gen1BiomomInHH = 40,
## // Gen1BiomomDeathAge = 41,
## // Gen1BiomomBirthYear = 42,
## // Gen1BiomomInHH1979 = 43,
## // Gen1BiomomBirthCountry = 44,
## // Gen1BiomomBirthState = 45,
## // Gen1AlwaysLivedWithBothBioparents = 50,
## }
##
## public enum MultipleBirth {
## No = 0,
## Twin = 2,
## Trip = 3,
## // TwinOrTrip = 4, // Currently Then Gen1 algorithm doesn't distinguish.
## DoNotKnow = 255,
## }
##
## public enum RaceCohort {
## Black = 1,
## Hispanic = 2,
## Mixed = 3,
## Nbnh = 4,
## }
##
## public enum RosterGen1 {
## valid_skip = -4,
## do_not_know = -2,
## refusal = -1,
## self = 0,
## wife = 1,
## husband = 2,
## mother = 3,
## father = 4,
## mother_step = 7,
## father_step = 8,
## mother_adoptive = 5,
## father_adoptive = 6,
## mother_foster = 9,
## father_foster = 10,
## mother_in_law = 11,
## father_in_law = 12,
## sister_full = 13,
## brother_full = 14,
## sister_half_same_mother = 15,
## sister_half_same_father = 16,
## sister_half_unsure = 17,
## brother_half_same_mother = 18,
## brother_half_same_father = 19,
## brother_half_unsure = 20,
## sister_step = 21,
## brother_step = 22,
## sister_adoptive = 23,
## brother_adoptive = 24,
## sister_foster = 25,
## brother_foster = 26,
## brother_in_law = 27,
## sister_in_law = 28,
## grandmother_maternal = 29,
## grandmother_paternal = 30,
## grandmother_social = 31,
## grandmother_unsure = 32,
## grandfather_maternal = 33,
## grandfather_paternal = 34,
## grandfather_social = 35,
## grandfather_unsure = 36,
## great_grandmother = 37,
## great_grandfather = 38,
## great_grandmother_social = 39,
## great_grandmother_unsure = 40,
## great_grandfather_maternal = 41,
## great_grandfather_paternal = 42,
## great_grandfather_social = 43,
## great_grandfather_unsure = 44,
## great_great_grandmother = 45,
## great_great_grandfather = 46,
## granddaughter = 47,
## grandson = 48,
## daughter_bio = 49,
## son_bio = 50,
## daughter_step = 51,
## son_step = 52,
## daughter_adoptive = 53,
## son_adoptive = 54,
## daughter_foster = 55,
## son_foster = 56,
## daughter_of_partner = 57,
## son_of_partner = 58,
## daughter_in_law = 59,
## son_in_law = 60,
## grandmother_in_law = 61,
## grandfather_in_law = 62,
## aunt_in_law = 63,
## uncle_in_law = 64,
## cousin_in_law = 65,
## great_grandmother_in_law = 66,
## great_grandfather_in_law = 67,
## roommate = 68,
## partner = 69,
## aunt_unsure = 70,
## great_aunt = 71,
## uncle_unsure = 72,
## great_uncle = 73,
## niece_unsure = 74,
## niece_step = 75,
## niece_foster = 76,
## niece_adoptive = 77,
## nephew_unsure = 78,
## nephew_step = 79,
## nephew_foster = 80,
## nephew_adoptive = 81,
## cousin_female_unsure = 82,
## cousin_male_unsure = 83,
## relative_other = 84,
## nonrelative_other = 85,
## great_grandson = 86,
## great_granddaughter = 87,
## relationship_missing = 99,
## }
##
## public enum Tristate {
## No = 0,
## Yes = 1,
## DoNotKnow = 255,
## }
##
## public enum YesNo {
## ValidSkipOrNoInterviewOrNotInSurvey = -6,
## InvalidSkip = -3,
## DoNotKnow = -2,
## Refusal = -1,
## No = 0,
## Yes = 1,
## }
</code></pre>
<pre><code class="r"># Sniff out problems
if( !shallow_only ) {
d_extract_source <- ds_file %>%
dplyr::filter(name=="LUExtractSource") %>%
dplyr::pull(entries) %>%
purrr::flatten_df()
d_item <- ds_file %>%
dplyr::filter(name=="item") %>%
dplyr::pull(entries) %>%
purrr::flatten_df()
checkmate::assert_integer( d_item$ID , lower=1, upper=2^15 , any.missing=F, unique=T)
checkmate::assert_character(d_item$Label , pattern="^\\w+" , any.missing=F, unique=T)
d_variable <- ds_file %>%
dplyr::filter(name=="variable") %>%
dplyr::pull(entries) %>%
purrr::flatten_df() %>%
dplyr::mutate(
item_found = (ExtractSource %in% d_extract_source$ID),
extract_found = (Item %in% d_item$ID),
unique_index = paste(Item, SurveyYear, LoopIndex1, LoopIndex2)
) %>%
dplyr::group_by(unique_index) %>%
dplyr::mutate(
unique_index_violation = (1L < n())
) %>%
dplyr::ungroup()
pattern_unique_index <- "^\\d{1,5} \\d{4} \\d{1,2} \\d{1,2}$"
checkmate::assert_character(d_variable$VariableCode , pattern="^[A-Z]\\d{7}$" , any.missing=F, unique=T)
checkmate::assert_integer( d_variable$Item , lower=0 , any.missing=F)
checkmate::assert_logical( d_variable$item_found , any.missing=F)
testit::assert("All items referenced from the variables should be in the item table.", all(d_variable$item_found))
testit::assert("All extract sources referenced from the variables should be in the item table.", all(d_variable$extract_found))
checkmate::assert_character(d_variable$unique_index , pattern=pattern_unique_index , any.missing=F, unique=T)
rm(d_item, d_variable)
}
</code></pre>
<pre><code class="r"># lst_ds %>%
# purrr::map(function(x)paste(names(x)))
ds_table_process <- ds_table %>%
dplyr::filter(schema_name == "Process") %>%
dplyr::mutate(
# sql_truncate = glue::glue("TRUNCATE TABLE {schema_name}.{table_name};")
sql_truncate = glue::glue("DELETE FROM {schema_name}.{table_name};")
)
# Open channel
channel <- open_dsn_channel_odbc(study)
DBI::dbGetInfo(channel)
</code></pre>
<pre><code>## $dbname
## [1] "NlsyLinks97"
##
## $dbms.name
## [1] "Microsoft SQL Server"
##
## $db.version
## [1] "13.00.4206"
##
## $username
## [1] "dbo"
##
## $host
## [1] ""
##
## $port
## [1] ""
##
## $sourcename
## [1] "local-nlsy-links-97"
##
## $servername
## [1] "GIMBLE\\EXPRESS_2016"