-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathday_two.html
888 lines (799 loc) · 32.8 KB
/
day_two.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="dcterms.date" content="2018-06-20" />
<title>How to Read, Write, and Google for Success in Coding</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js-3.3.0.1/css/reveal.css"/>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #0000ff; } /* Keyword */
code > span.ch { color: #008080; } /* Char */
code > span.st { color: #008080; } /* String */
code > span.co { color: #008000; } /* Comment */
code > span.ot { color: #ff4000; } /* Other */
code > span.al { color: #ff0000; } /* Alert */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #008000; font-weight: bold; } /* Warning */
code > span.cn { } /* Constant */
code > span.sc { color: #008080; } /* SpecialChar */
code > span.vs { color: #008080; } /* VerbatimString */
code > span.ss { color: #008080; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { } /* Variable */
code > span.cf { color: #0000ff; } /* ControlFlow */
code > span.op { } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #ff4000; } /* Preprocessor */
code > span.do { color: #008000; } /* Documentation */
code > span.an { color: #008000; } /* Annotation */
code > span.cv { color: #008000; } /* CommentVar */
code > span.at { } /* Attribute */
code > span.in { color: #008000; } /* Information */
</style>
<link rel="stylesheet" href="reveal.js-3.3.0.1/css/theme/simple.css" id="theme">
<!-- some tweaks to reveal css -->
<style type="text/css">
.reveal h1 { font-size: 2.0em; }
.reveal h2 { font-size: 1.5em; }
.reveal h3 { font-size: 1.25em; }
.reveal h4 { font-size: 1em; }
.reveal .slides>section,
.reveal .slides>section>section {
padding: 0px 0px;
}
.reveal table {
border-width: 1px;
border-spacing: 2px;
border-style: dotted;
border-color: gray;
border-collapse: collapse;
font-size: 0.7em;
}
.reveal table th {
border-width: 1px;
padding-left: 10px;
padding-right: 25px;
font-weight: bold;
border-style: dotted;
border-color: gray;
}
.reveal table td {
border-width: 1px;
padding-left: 10px;
padding-right: 25px;
border-style: dotted;
border-color: gray;
}
</style>
<style type="text/css">code{white-space: pre;}</style>
<!-- Printing and PDF exports -->
<script id="paper-css" type="application/dynamic-css">
/* Default Print Stylesheet Template
by Rob Glazebrook of CSSnewbie.com
Last Updated: June 4, 2008
Feel free (nay, compelled) to edit, append, and
manipulate this file as you see fit. */
@media print {
/* SECTION 1: Set default width, margin, float, and
background. This prevents elements from extending
beyond the edge of the printed page, and prevents
unnecessary background images from printing */
html {
background: #fff;
width: auto;
height: auto;
overflow: visible;
}
body {
background: #fff;
font-size: 20pt;
width: auto;
height: auto;
border: 0;
margin: 0 5%;
padding: 0;
overflow: visible;
float: none !important;
}
/* SECTION 2: Remove any elements not needed in print.
This would include navigation, ads, sidebars, etc. */
.nestedarrow,
.controls,
.fork-reveal,
.share-reveal,
.state-background,
.reveal .progress,
.reveal .backgrounds {
display: none !important;
}
/* SECTION 3: Set body font face, size, and color.
Consider using a serif font for readability. */
body, p, td, li, div {
font-size: 20pt!important;
font-family: Georgia, "Times New Roman", Times, serif !important;
color: #000;
}
/* SECTION 4: Set heading font face, sizes, and color.
Differentiate your headings from your body text.
Perhaps use a large sans-serif for distinction. */
h1,h2,h3,h4,h5,h6 {
color: #000!important;
height: auto;
line-height: normal;
font-family: Georgia, "Times New Roman", Times, serif !important;
text-shadow: 0 0 0 #000 !important;
text-align: left;
letter-spacing: normal;
}
/* Need to reduce the size of the fonts for printing */
h1 { font-size: 28pt !important; }
h2 { font-size: 24pt !important; }
h3 { font-size: 22pt !important; }
h4 { font-size: 22pt !important; font-variant: small-caps; }
h5 { font-size: 21pt !important; }
h6 { font-size: 20pt !important; font-style: italic; }
/* SECTION 5: Make hyperlinks more usable.
Ensure links are underlined, and consider appending
the URL to the end of the link for usability. */
a:link,
a:visited {
color: #000 !important;
font-weight: bold;
text-decoration: underline;
}
/*
.reveal a:link:after,
.reveal a:visited:after {
content: " (" attr(href) ") ";
color: #222 !important;
font-size: 90%;
}
*/
/* SECTION 6: more reveal.js specific additions by @skypanther */
ul, ol, div, p {
visibility: visible;
position: static;
width: auto;
height: auto;
display: block;
overflow: visible;
margin: 0;
text-align: left !important;
}
.reveal pre,
.reveal table {
margin-left: 0;
margin-right: 0;
}
.reveal pre code {
padding: 20px;
border: 1px solid #ddd;
}
.reveal blockquote {
margin: 20px 0;
}
.reveal .slides {
position: static !important;
width: auto !important;
height: auto !important;
left: 0 !important;
top: 0 !important;
margin-left: 0 !important;
margin-top: 0 !important;
padding: 0 !important;
zoom: 1 !important;
overflow: visible !important;
display: block !important;
text-align: left !important;
-webkit-perspective: none;
-moz-perspective: none;
-ms-perspective: none;
perspective: none;
-webkit-perspective-origin: 50% 50%;
-moz-perspective-origin: 50% 50%;
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.reveal .slides section {
visibility: visible !important;
position: static !important;
width: auto !important;
height: auto !important;
display: block !important;
overflow: visible !important;
left: 0 !important;
top: 0 !important;
margin-left: 0 !important;
margin-top: 0 !important;
padding: 60px 20px !important;
z-index: auto !important;
opacity: 1 !important;
page-break-after: always !important;
-webkit-transform-style: flat !important;
-moz-transform-style: flat !important;
-ms-transform-style: flat !important;
transform-style: flat !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
transform: none !important;
-webkit-transition: none !important;
-moz-transition: none !important;
-ms-transition: none !important;
transition: none !important;
}
.reveal .slides section.stack {
padding: 0 !important;
}
.reveal section:last-of-type {
page-break-after: avoid !important;
}
.reveal section .fragment {
opacity: 1 !important;
visibility: visible !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
transform: none !important;
}
.reveal section img {
display: block;
margin: 15px 0px;
background: rgba(255,255,255,1);
border: 1px solid #666;
box-shadow: none;
}
.reveal section small {
font-size: 0.8em;
}
}
</script>
<script id="pdf-css" type="application/dynamic-css">
/**
* This stylesheet is used to print reveal.js
* presentations to PDF.
*
* https://github.com/hakimel/reveal.js#pdf-export
*/
* {
-webkit-print-color-adjust: exact;
}
body {
margin: 0 auto !important;
border: 0;
padding: 0;
float: none !important;
overflow: visible;
}
html {
width: 100%;
height: 100%;
overflow: visible;
}
/* Remove any elements not needed in print. */
.nestedarrow,
.reveal .controls,
.reveal .progress,
.reveal .playback,
.reveal.overview,
.fork-reveal,
.share-reveal,
.state-background {
display: none !important;
}
h1, h2, h3, h4, h5, h6 {
text-shadow: 0 0 0 #000 !important;
}
.reveal pre code {
overflow: hidden !important;
font-family: Courier, 'Courier New', monospace !important;
}
ul, ol, div, p {
visibility: visible;
position: static;
width: auto;
height: auto;
display: block;
overflow: visible;
margin: auto;
}
.reveal {
width: auto !important;
height: auto !important;
overflow: hidden !important;
}
.reveal .slides {
position: static;
width: 100%;
height: auto;
left: auto;
top: auto;
margin: 0 !important;
padding: 0 !important;
overflow: visible;
display: block;
-webkit-perspective: none;
-moz-perspective: none;
-ms-perspective: none;
perspective: none;
-webkit-perspective-origin: 50% 50%; /* there isn't a none/auto value but 50-50 is the default */
-moz-perspective-origin: 50% 50%;
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.reveal .slides section {
page-break-after: always !important;
visibility: visible !important;
position: relative !important;
display: block !important;
position: relative !important;
margin: 0 !important;
padding: 0 !important;
box-sizing: border-box !important;
min-height: 1px;
opacity: 1 !important;
-webkit-transform-style: flat !important;
-moz-transform-style: flat !important;
-ms-transform-style: flat !important;
transform-style: flat !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
transform: none !important;
}
.reveal section.stack {
margin: 0 !important;
padding: 0 !important;
page-break-after: avoid !important;
height: auto !important;
min-height: auto !important;
}
.reveal img {
box-shadow: none;
}
.reveal .roll {
overflow: visible;
line-height: 1em;
}
/* Slide backgrounds are placed inside of their slide when exporting to PDF */
.reveal section .slide-background {
display: block !important;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
}
/* All elements should be above the slide-background */
.reveal section>* {
position: relative;
z-index: 1;
}
/* Display slide speaker notes when 'showNotes' is enabled */
.reveal .speaker-notes-pdf {
display: block;
width: 100%;
max-height: none;
left: auto;
top: auto;
z-index: 100;
}
/* Display slide numbers when 'slideNumber' is enabled */
.reveal .slide-number-pdf {
display: block;
position: absolute;
font-size: 14px;
}
</script>
<script>
var style = document.createElement( 'style' );
style.type = 'text/css';
var style_script_id = window.location.search.match( /print-pdf/gi ) ? 'pdf-css' : 'paper-css';
var style_script = document.getElementById(style_script_id).text;
style.innerHTML = style_script;
document.getElementsByTagName('head')[0].appendChild(style);
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">How to Read, Write, and Google for Success in Coding</h1>
<h2 class="author"><div style="white-space: pre-line;">Christopher Skovron and Jon Atwell
Northwestern University</div></h2>
<h3 class="date">June 20, 2018</h3>
</section>
<section id="learning-to-do-computational-research-involves-learning-to-write-and-read-different-things-than-you-are-used-to" class="slide level2">
<h2>Learning to do computational research involves learning to write and read different things than you are used to</h2>
<section>
</section>
</section>
<section id="you-probably-hear-a-lot-about-clean-code" class="slide level2">
<h2>You probably hear a lot about “clean” code</h2>
</section>
<section id="most-of-that-is-bullshit-and-preening" class="slide level2">
<h2>Most of that is bullshit and preening</h2>
<ul>
<li>unless you are working in industry in a setting where things need to highly scale</li>
<li>remember the point from Day One about human scale</li>
</ul>
</section>
<section id="in-a-year-or-five-years-you-will-look-back-on-your-past-selfs-code-and-be-horrified" class="slide level2">
<h2>In a year or five years, you will look back on your past self’s code and be horrified</h2>
<p><img src="images/sarahb_faultsiez.png" alt="From @sarahbouchat’s twitter" /></p>
</section>
<section id="set-yourself-realistic-goals-in-coding" class="slide level2">
<h2>Set yourself realistic goals in coding</h2>
<ul>
<li>Acquire data</li>
<li>Clean it in (tidy) forms ready for analysis</li>
<li>Analyze</li>
<li>Visualize and communicate</li>
</ul>
</section>
<section id="these-goals-animate-todays-lesson-on-how-to-teach-yourself-and-tomorrows-lesson-on-getting-organized" class="slide level2">
<h2>These goals animate today’s lesson, on how to teach yourself, and tomorrow’s lesson on “getting organized”</h2>
<ul>
<li>These goals require lots of practice. Halfway between muscle memory and an art form</li>
</ul>
</section>
<section id="reading-and-writing-documents-related-to-coding" class="slide level2">
<h2>Reading and writing documents related to coding</h2>
<ul>
<li>You will be reading new kinds of documentation, vignettes, examples, error messages</li>
<li>These will seem confusing at first</li>
<li>There are strategies, but nothing can beat practice</li>
</ul>
</section>
<section id="your-goals-in-writing-code-are-more-modest" class="slide level2">
<h2>Your goals in writing code are more modest</h2>
<ul>
<li>Does this do what I need it to do in a reasonably computationally efficient manner?</li>
<li>Will my future self understand it?</li>
<li>Will my collaborators and/or replicators understand it?</li>
<li>Have I written in such a way that will prevent me from making mistakes? We will address each of these goals in order.</li>
</ul>
</section>
<section id="code-should-be" class="slide level2">
<h2>Code should be</h2>
<ul>
<li>Easily understood by humans</li>
<li>Relatively consistent</li>
<li>Able to be adapted to new situations</li>
</ul>
</section>
<section id="some-resources-to-orient-you-to-best-practicies-in-writing-code" class="slide level2">
<h2>Some resources to orient you to best practicies in writing code</h2>
<ul>
<li>Read points 1-8 of <a href="https://www.r-bloggers.com/r-best-practices-r-you-writing-the-r-way/">this guide</a> (specific to R but applies to other languages)</li>
<li><a href="http://adv-r.had.co.nz/Style.html">Hadley Wickham’s R style guide</a></li>
<li><a href="https://swcarpentry.github.io/r-novice-inflammation/06-best-practices-R/">Another good resource on R best practices.</a></li>
</ul>
</section>
<section id="pick-good-names" class="slide level2">
<h2>Pick good names</h2>
<ul>
<li>You might be tempted to use abbreviations or non-words to save yourself from typing the same characters over and over</li>
<li>With modern IDEs, tab completion means this is not a big issue</li>
<li>Choose names that are legible, clear, and precise</li>
<li>Name functions what they do, name variables what they are</li>
</ul>
</section>
<section id="good-and-bad-names" class="slide level2">
<h2>Good and bad names</h2>
<p>In R, dots are common, underscores are ok:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">## a few bad variable names from my past work
incspendtran
V101
gender <span class="co"># if coded as one or zero, as a factor I'd accept this </span>
## better names
increase.spending.transportation
respondent.id
female <span class="co"># coded 1 if female</span></code></pre></div>
</section>
<section id="similar-variables-should-have-similar-names" class="slide level2">
<h2>Similar variables should have similar names</h2>
<ul>
<li>For example, my candidates’ perceptions of things always begin with <code>perc.</code></li>
<li>Next, geography, are they perceiving district, <code>perc.district</code>, or state, <code>perc.state</code></li>
<li>Sometimes they are perceiving opinion within a party: <code>perc.district.dem</code></li>
<li>Then the issue: <code>perc.district.dem.marriage</code> means their district-level perception of support for same-sex marriage. <code>perc.district.guns.banassault</code> is district-level support for banning assault weapons. There’s also <code>guns.background.check</code>….</li>
<li>This lets me use things like <code>grep()</code> to grab variables that are similar</li>
</ul>
</section>
<section id="commenting" class="slide level2">
<h2>Commenting</h2>
<ul>
<li>Messages to all of your audiences – most importantly to yourself</li>
<li>Say what you’re doing in plain words and why you’re doing it</li>
<li>People differ a lot in their commenting preferences</li>
<li>Find what’s comfortable for you, let it evolve</li>
<li>A good rule of thumb - if it’s not obvious what’s going on from a quick skim of the code, comment it</li>
</ul>
</section>
<section id="principles-of-good-commenting" class="slide level2">
<h2>Principles of good commenting</h2>
<ul>
<li>Don’t comment things that are painfully obvious</li>
<li>But most things won’t be painfully obvious</li>
<li>Comment to introduce each new section of code or each major task</li>
<li>If you write a new function, leave a comment explaining what it does</li>
</ul>
</section>
<section id="introduce-each-new-subsection-of-code-with-a-comment" class="slide level2">
<h2>Introduce each new subsection of code with a comment</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># plot partisan estimates against one another</span>
<span class="co"># voters only</span>
g =<span class="st"> </span><span class="kw">ggplot</span>(ncs, <span class="kw">aes</span>(voted.pid7.dem)) <span class="op">+</span>
<span class="st"> </span><span class="kw">geom_density</span>(<span class="dt">color =</span> <span class="st">'blue'</span>) <span class="op">+</span><span class="st"> </span>
<span class="st"> </span><span class="kw">theme_classic</span>() <span class="op">+</span>
<span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.position=</span><span class="st">'none'</span>) <span class="op">+</span>
<span class="st"> </span><span class="kw">xlim</span>(<span class="dv">0</span>,<span class="dv">1</span>) <span class="op">+</span>
<span class="st"> </span><span class="kw">theme</span>(<span class="dt">axis.title=</span><span class="kw">element_text</span>(<span class="dt">size=</span><span class="dv">8</span>), <span class="dt">plot.title =</span> <span class="kw">element_text</span>(<span class="dt">hjust=</span><span class="fl">0.5</span>, <span class="dt">size =</span> <span class="dv">10</span>)) <span class="op">+</span>
<span class="st"> </span><span class="kw">geom_density</span>(<span class="kw">aes</span>(voted.pid7.rep), <span class="dt">color =</span> <span class="st">'red'</span>) <span class="op">+</span>
<span class="st"> </span><span class="kw">ggtitle</span>(<span class="st">"Distribution of electorate partisanship estimates"</span>) <span class="op">+</span>
<span class="st"> </span><span class="kw">xlab</span>(<span class="st">"Percent of voters in district belonging to each party"</span>)</code></pre></div>
</section>
<section id="more-examples-of-comments-form-my-code" class="slide level2">
<h2>More examples of comments form my code</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">### POSTSTRATIFICATION <span class="al">###</span>
<span class="co"># set up poststratification file and poststratify 2014 MRSP models </span>
<span class="co"># level is upper or lower districts, pid.level is 3 or 7 point item </span>
get.cell.predictions <-<span class="st"> </span><span class="cf">function</span>(individual.model,
pid.var, <span class="co"># e.g., 'pid3.dem'</span>
pstrat){
<span class="co"># district random effects need zeros for missing dists</span>
district.ranefs <-<span class="st"> </span><span class="kw">ranef</span>(individual.model)<span class="op">$</span>modgeoid
missing.districts <-<span class="st"> </span><span class="kw">setdiff</span>(<span class="kw">unique</span>(pstrat<span class="op">$</span>modgeoid), <span class="kw">rownames</span>(district.ranefs))
missing.districts.df <-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">district =</span> missing.districts)
<span class="kw">rownames</span>(missing.districts.df) <-<span class="st"> </span>missing.districts.df<span class="op">$</span>district
missing.districts.df<span class="op">$</span><span class="st">`</span><span class="dt">(Intercept)</span><span class="st">`</span> <-<span class="st"> </span><span class="dv">0</span>
missing.districts.df <-<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(missing.districts.df, <span class="op">-</span>district)
district.ranefs <-<span class="st"> </span><span class="kw">rbind.data.frame</span>(district.ranefs, missing.districts.df)
<span class="co"># </span><span class="al">NOTE</span><span class="co">: make sure AK and HI is working</span></code></pre></div>
</section>
<section id="more-comments-from-that-r-script" class="slide level2">
<h2>More comments from that R script</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># divide within proportions grouped by party</span>
<span class="co"># and district to get dist-party estimates </span>
pstrat.upper =<span class="st"> </span>pstrat <span class="op">%>%</span><span class="st"> </span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">filter</span>(<span class="kw">grepl</span>(<span class="st">"U"</span>, modgeoid)) <span class="op">%>%</span><span class="st"> </span>
<span class="st"> </span><span class="kw">cbind</span>(upper.cell.predictions) <span class="op">%>%</span><span class="st"> </span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(<span class="op">-</span>X)
pstrat.lower =<span class="st"> </span>pstrat <span class="op">%>%</span><span class="st"> </span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">filter</span>(<span class="kw">grepl</span>(<span class="st">"L"</span>, modgeoid)) <span class="op">%>%</span><span class="st"> </span>
<span class="st"> </span><span class="kw">cbind</span>(lower.cell.predictions) <span class="op">%>%</span><span class="st"> </span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(<span class="op">-</span>X)</code></pre></div>
</section>
<section id="commenting-sounds-easy-in-the-abstract" class="slide level2">
<h2>Commenting sounds easy in the abstract</h2>
<ul>
<li>You’ll be cruising along writing code (no, really, eventually you will) and not feel like stopping to write comments</li>
<li>Things will seem really obvious when you write them despite being not obvious to those who come after, including your future self</li>
<li>Consistently remind yourself to leave comments</li>
</ul>
</section>
<section id="how-to-find-help" class="slide level2">
<h2>How to find help</h2>
<ul>
<li>Three problems:
<ul>
<li>You don’t know where to start</li>
<li>You write code and it gives the wrong output</li>
<li>You write code and it throws an error</li>
</ul></li>
</ul>
</section>
<section id="error-messages" class="slide level2">
<h2>Error messages</h2>
<ul>
<li>Can be helpful or inscrutable</li>
<li>Often googling them will get you right to the solution or an explanation</li>
<li><a href="http://www.dummies.com/programming/r/how-to-read-errors-and-warnings-in-r/">A guide on understanding the structure of R error messages</a></li>
</ul>
</section>
<section id="expect-to-constantly-be-searching-for-help" class="slide level2">
<h2>Expect to constantly be searching for help</h2>
<ul>
<li>There’s way too much to remember, we offload that knowledge to the internet and elsewhere</li>
<li>Messing up is the best way to learn when coding</li>
<li>Get comfortable with spending a lot of time googling</li>
</ul>
</section>
<section id="do-due-diligence-before-googling-aimlessly" class="slide level2">
<h2>Do due diligence before googling aimlessly</h2>
<ul>
<li>You may be able to Google a solution, but that is sort of the being-given-a-fish way. You want to learn to fish.</li>
<li>The best ways to teach yourself are to code a lot and read a lot of examples</li>
<li>It’s a really slow process</li>
</ul>
</section>
<section id="steal-intelligently" class="slide level2">
<h2>Steal intelligently</h2>
<ul>
<li>Figure out who’s doing similar tasks to you and look for tutorials online</li>
<li>Steal people’s replication code (But be critical of it!)</li>
</ul>
</section>
<section id="how-to-read-documentation" class="slide level2">
<h2>How to read documentation</h2>
<ul>
<li>Most documentation will show you a function and various <em>parameters</em></li>
<li>It’s important to understand different classes of data structures and variable classes in order to effectively use documentation</li>
<li>In R, you’ll want to learn the differences between</li>
</ul>
</section>
<section id="find-vignettes-and-lessons-written-by-others" class="slide level2">
<h2>Find vignettes and lessons written by others</h2>
<ul>
<li>You’ll want to read package documentation, but more didactic examples are helpful too</li>
<li>In R world these are called vignettes, you’ll also find “tutorials”</li>
<li>Many github repositories have vignettes and usage examples attached to them.</li>
<li><a href="https://cran.r-project.org/web/packages/broom/vignettes/broom.html">An example of a nice package vignette, for <code>broom</code></a></li>
<li><a href="https://cran.r-project.org/web/packages/dotwhisker/vignettes/dotwhisker-vignette.html">Another nice package vignette, for <code>dotwhisker</code></a></li>
</ul>
</section>
<section id="build-up-a-library-of-cheats" class="slide level2">
<h2>Build up a library of cheats</h2>
<ul>
<li>Bookmark useful help pages</li>
<li>Make yourself a notebook of examples of code. Have a dropbox folder where you save snippets that do tasks you frequently do.</li>
<li>I have things like group-level proportions that I frequently do for summary statistics</li>
<li>Also have my favorite ggplot settings, etc</li>
<li>Pillage old code for new projects (But be careful! You or your software have probably improved, so writing it anew could be a good learning experience and/or improve efficiency)</li>
</ul>
</section>
<section id="someone-else-has-had-your-problem-before" class="slide level2">
<h2>Someone else has had your problem before</h2>
<ul>
<li>You will almost never need to post your own question to a mailing list or to StackOverflow.</li>
<li>Someone has had a similar problem before, you just need to know how to find it</li>
<li>People might have similar but slightly different problems that you can</li>
</ul>
</section>
<section id="figuring-out-your-google-query" class="slide level2">
<h2>Figuring out your google query</h2>
<ul>
<li>Most of the time, you’re going to want to end up on StackOverflow. Often it’s good just to search within SO</li>
<li>Look for tutorials if you find yourself frequently using a package: If you find yourself working with lots of strings, set aside an afternoon to look at everything written on <code>stringr</code></li>
</ul>
</section>
<section id="effectively-searching-stackoverflow" class="slide level2">
<h2>Effectively searching StackOverflow</h2>
<ul>
<li>I’ve found the best queries are action verb type things:
<ul>
<li>Merge two data frames on multiple variables R</li>
<li>Rename columns with similar names R</li>
</ul></li>
</ul>
</section>
<section id="googling-tips" class="slide level2">
<h2>Googling tips</h2>
<ul>
<li>Include your language!</li>
<li>StackOverflow will know the letter R means the language. In some google queries you might want to</li>
</ul>
</section>
<section id="what-youll-find-on-stackoverflow" class="slide level2">
<h2>What you’ll find on StackOverflow</h2>
<p><img src="images/stackoverflow-examples/so-1.png" /></p>
</section>
<section id="what-youll-find-on-stackoverflow-1" class="slide level2">
<h2>What you’ll find on StackOverflow</h2>
<p><img src="images/stackoverflow-examples/so-2.png" /></p>
</section>
<section id="what-youll-find-on-stackoverflow-2" class="slide level2">
<h2>What you’ll find on StackOverflow</h2>
<p><img src="images/stackoverflow-examples/so-3.png" /></p>
</section>
<section id="what-youll-find-on-stackoverflow-3" class="slide level2">
<h2>What you’ll find on StackOverflow</h2>
<p><img src="images/stackoverflow-examples/so-4.png" /></p>
</section>
<section id="what-youll-find-on-stackoverflow-4" class="slide level2">
<h2>What you’ll find on StackOverflow</h2>
<p><img src="images/stackoverflow-examples/so-5.png" /></p>
</section>
<section id="use-built-in-help" class="slide level2">
<h2>Use built-in help</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">?lm
?read.csv
?dplyr<span class="op">::</span>rename</code></pre></div>
</section>
<section id="built-in-help-will" class="slide level2">
<h2>Built-in help will</h2>
<ul>
<li>Tell you how functions work, to varying degrees of helpfulness</li>
<li>Often provide some examples of how functions work</li>
<li>Often still leave you clueless and needing to Google around some more</li>
</ul>
</section>
<section id="not-so-useful-help" class="slide level2">
<h2>Not-so-useful help</h2>
<p><img src="images/builtin-help/grep-1.png" alt="The help file for grep is not very useful for novices" /></p>
</section>
<section id="not-so-useful-help-1" class="slide level2">
<h2>Not-so-useful help</h2>
<p><img src="images/builtin-help/grep-2.png" alt="The help file for grep is not very useful for novices" /></p>
</section>
<section id="some-builtin-help-is-more-useful" class="slide level2">
<h2>Some builtin help is more useful</h2>
<p><img src="images/builtin-help/amce-1.png" alt="The amce function does one thing and is well-documented." /></p>
</section>
<section id="some-builtin-help-is-more-useful-1" class="slide level2">
<h2>Some builtin help is more useful</h2>
<p><img src="images/builtin-help/amce-2.png" alt="The amce function does one thing and is well-documented." /></p>
</section>
<section id="some-builtin-help-is-more-useful-2" class="slide level2">
<h2>Some builtin help is more useful</h2>
<p><img src="images/builtin-help/amce-3.png" alt="The amce function does one thing and is well-documented." /></p>
</section>
<section id="some-builtin-help-is-more-useful-3" class="slide level2">
<h2>Some builtin help is more useful</h2>
<p><img src="images/builtin-help/amce-4.png" alt="The amce function does one thing and is well-documented." /></p>
</section>
<section id="asking-for-help" class="slide level2">
<h2>Asking for help</h2>
<ul>
<li>You will want a “minimal working example”</li>
<li><a href="https://www.jaredknowles.com/journal/2013/5/27/writing-a-minimal-working-example-mwe-in-r">Here’s a good guide for writing one in R from Jared Knowles</a></li>
<li>The most efficient way to ask for help, in exponentially decreasing order: Ask Google, ask people you know, ask strangers online</li>
</ul>
</section>
<section id="it-gets-better" class="slide level2">
<h2>IT GETS BETTER</h2>
</section>
</div>
</div>
<script src="reveal.js-3.3.0.1/lib/js/head.min.js"></script>
<script src="reveal.js-3.3.0.1/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// Push each slide change to the browser history
history: true,
// Vertical centering of slides
center: false,
// Transition style
transition: 'none', // none/fade/slide/convex/concave/zoom
// Transition style for full page slide backgrounds
backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
]
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
<script>
(function() {
if (window.jQuery) {
Reveal.addEventListener( 'slidechanged', function(event) {
window.jQuery(event.previousSlide).trigger('hidden');
window.jQuery(event.currentSlide).trigger('shown');
});
}
})();
</script>
</body>
</html>