forked from AdamWilsonLabEDU/SpatialDataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPS_07_help.html
More file actions
826 lines (741 loc) · 38.4 KB
/
PS_07_help.html
File metadata and controls
826 lines (741 loc) · 38.4 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>HELP!</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="externals/reveal.js-3.3.0.1/css/reveal.css"/>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; position: absolute; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; }
pre.numberSource a.sourceLine:empty
{ position: absolute; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: absolute; left: -5em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="externals/reveal.js-3.3.0.1/css/theme/white.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>
<link rel="stylesheet" href="reveal.css"/>
<!-- 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>
<link href="externals/font-awesome-5.0.13/css/fa-svg-with-js.css" rel="stylesheet" />
<script src="externals/font-awesome-5.0.13/js/fontawesome-all.min.js"></script>
<script src="externals/font-awesome-5.0.13/js/fa-v4-shims.min.js"></script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">HELP!</h1>
</section>
<section id="got-problems" class="slide level2">
<h2>Got Problems?</h2>
<p><img data-src="https://imgs.xkcd.com/comics/error_code.png" /></p>
</section>
<section><section id="strange-errors" class="title-slide slide level1"><h1>Strange Errors</h1></section><section id="examples-from-stack-overflow" class="slide level2">
<h2>Examples from Stack Overflow</h2>
<p>This is the error messages I get…</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="op">></span><span class="st"> </span><span class="kw">setwd</span>(<span class="st">"H:/user/george"</span>)</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="st">"Error: unexpected input in "</span><span class="kw">setwd</span>(<span class="st">"H:/XX/XXX"</span>)</a>
<a class="sourceLine" id="cb1-3" data-line-number="3"><span class="st">"Error: unexpected input in "</span></a>
<a class="sourceLine" id="cb1-4" data-line-number="4"><span class="op">></span><span class="st"> </span>GWS <-<span class="st"> </span><span class="kw">read.csv</span>(<span class="st">"X.csv"</span>, <span class="dt">header =</span> <span class="ot">TRUE</span>, <span class="dt">sep =</span> <span class="st">","</span>, <span class="dt">stringsAsFactors =</span></a>
<a class="sourceLine" id="cb1-5" data-line-number="5"><span class="ot">FALSE</span>, <span class="dt">na.strings=</span><span class="kw">c</span>(<span class="st">""</span>,<span class="st">""</span>,<span class="st">"NA"</span>))</a>
<a class="sourceLine" id="cb1-6" data-line-number="6"><span class="st">"Error: unexpected input in "</span>GWS <-<span class="st"> </span><span class="kw">read.csv</span>(<span class="st">"X.csv"</span>, <span class="dt">header =</span> <span class="ot">TRUE</span>, <span class="dt">sep =</span></a>
<a class="sourceLine" id="cb1-7" data-line-number="7"><span class="st">","</span>, <span class="dt">stringsAsFactors =</span> <span class="ot">FALSE</span>, <span class="dt">na.strings=</span><span class="kw">c</span>(<span class="st">""</span>,<span class="st">""</span>,<span class="st">"NA"</span>))</a>
<a class="sourceLine" id="cb1-8" data-line-number="8"><span class="op">></span><span class="st"> </span>GWS <-<span class="st"> </span>GWS[<span class="kw">with</span>(GWS, <span class="kw">order</span>(d)), ]; <span class="kw">row.names</span>(GWS) <-<span class="st"> </span><span class="ot">NULL</span></a>
<a class="sourceLine" id="cb1-9" data-line-number="9">Error<span class="op">:</span><span class="st"> </span>object <span class="st">'GWS'</span> not found</a></code></pre></div>
</section><section id="another-one" class="slide level2">
<h2>Another one</h2>
<p>“Help, I’m getting an error and I don’t know what it means”</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="op">></span><span class="st"> </span>lm1=<span class="kw">lm</span>(cr<span class="op">~</span>tn,<span class="dt">data=</span>x)</a>
<a class="sourceLine" id="cb2-2" data-line-number="2">Error <span class="cf">in</span> <span class="kw">lm.fit</span>(x, y, <span class="dt">offset =</span> offset, <span class="dt">singular.ok =</span> singular.ok, ...) <span class="op">:</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-3" data-line-number="3"><span class="st"> </span><span class="ot">NA</span><span class="op">/</span><span class="ot">NaN</span><span class="op">/</span><span class="ot">Inf</span> <span class="cf">in</span> <span class="st">'y'</span></a>
<a class="sourceLine" id="cb2-4" data-line-number="4">In addition<span class="op">:</span><span class="st"> </span>Warning message<span class="op">:</span></a>
<a class="sourceLine" id="cb2-5" data-line-number="5">In <span class="kw">storage.mode</span>(v) <-<span class="st"> "double"</span> <span class="op">:</span><span class="st"> </span>NAs introduced by coercion</a></code></pre></div>
</section></section>
<section><section id="finding-help" class="title-slide slide level1"><h1>Finding Help</h1></section><section id="basic-resources" class="slide level2">
<h2>Basic Resources</h2>
<p><a href="https://www.r-project.org/help.html">Getting Help with R</a></p>
<iframe width="100%" height="500px" src="https://www.r-project.org/help.html">
</iframe>
</section><section id="help-files" class="slide level2">
<h2>Help Files</h2>
<iframe width="100%" height="500px" src="https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/mean">
</iframe>
</section><section id="vignettes" class="slide level2">
<h2>Vignettes</h2>
<p><a href="https://cran.r-project.org/web/packages/sf/index.html">sf: Simple Features for R</a></p>
<div class="embed-responsive embed-responsive">
<iframe class="embed-responsive-item" width="100%" height="500px" src="https://cran.r-project.org/web/packages/sf/index.html" allowfullscreen>
</iframe>
</div>
</section></section>
<section><section id="effective-problem-solving" class="title-slide slide level1"><h1>Effective Problem Solving</h1></section><section id="step-one-break-down-your-problem" class="slide level2">
<h2>Step one: Break down your problem</h2>
<ul>
<li>Break down your code (run bit by bit)!</li>
<li>Understand the data/inputs</li>
<li>Read the help files carefully</li>
<li>Try <code>traceback()</code></li>
</ul>
</section><section id="r-is-very-picky" class="slide level2">
<h2>R is very picky</h2>
<p>It expects you to give accurate instructions…</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1">reallystrangenme <-<span class="st"> </span><span class="kw">rnorm</span>(<span class="dv">10</span>)</a>
<a class="sourceLine" id="cb3-2" data-line-number="2">anothrstrngenme <-<span class="st"> </span><span class="dv">3</span><span class="op">+</span><span class="dv">5</span><span class="op">*</span>reallystrangenme<span class="op">+</span><span class="kw">rnorm</span>(<span class="dv">10</span>)</a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="kw">lm</span>(reallystrngenme<span class="op">~</span>anothrstrngenme)</a></code></pre></div>
<ul>
<li class="fragment"><code># Error: object 'reallystrngenme' not found</code></li>
</ul>
</section><section id="break-down-your-code" class="slide level2">
<h2>Break down your code</h2>
<p>Run bit by bit:</p>
<p><img data-src="img/run_part.png" /></p>
</section><section id="traceback" class="slide level2">
<h2>traceback</h2>
<p>Prints the call stack of the last uncaught error, i.e., the sequence of calls that lead to the error. This is useful when an error occurs with an unidentifiable error message.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1">pets=<span class="kw">c</span>(<span class="st">"dog"</span>,<span class="st">"cat"</span>,<span class="st">"fish"</span>)</a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="kw">lm</span>(pets<span class="op">~</span><span class="dv">1</span><span class="op">:</span><span class="dv">5</span>)</a>
<a class="sourceLine" id="cb4-3" data-line-number="3"></a>
<a class="sourceLine" id="cb4-4" data-line-number="4">Error <span class="cf">in</span> <span class="kw">terms.formula</span>(formula, <span class="dt">data =</span> data) <span class="op">:</span></a>
<a class="sourceLine" id="cb4-5" data-line-number="5"><span class="st"> </span>invalid model formula <span class="cf">in</span> ExtractVars</a>
<a class="sourceLine" id="cb4-6" data-line-number="6"></a>
<a class="sourceLine" id="cb4-7" data-line-number="7"><span class="kw">traceback</span>()</a>
<a class="sourceLine" id="cb4-8" data-line-number="8"></a>
<a class="sourceLine" id="cb4-9" data-line-number="9"> <span class="dv">7</span><span class="op">:</span><span class="st"> </span><span class="kw">terms.formula</span>(formula, <span class="dt">data =</span> data)</a>
<a class="sourceLine" id="cb4-10" data-line-number="10"> <span class="dv">6</span><span class="op">:</span><span class="st"> </span><span class="kw">terms</span>(formula, <span class="dt">data =</span> data)</a>
<a class="sourceLine" id="cb4-11" data-line-number="11"> <span class="dv">5</span><span class="op">:</span><span class="st"> </span><span class="kw">model.frame.default</span>(<span class="dt">formula =</span> pets <span class="op">~</span><span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">5</span>, <span class="dt">drop.unused.levels =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb4-12" data-line-number="12"> <span class="dv">4</span><span class="op">:</span><span class="st"> </span>stats<span class="op">::</span><span class="kw">model.frame</span>(<span class="dt">formula =</span> pets <span class="op">~</span><span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">5</span>, <span class="dt">drop.unused.levels =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb4-13" data-line-number="13"> <span class="dv">3</span><span class="op">:</span><span class="st"> </span><span class="kw">eval</span>(mf, <span class="kw">parent.frame</span>())</a>
<a class="sourceLine" id="cb4-14" data-line-number="14"> <span class="dv">2</span><span class="op">:</span><span class="st"> </span><span class="kw">eval</span>(mf, <span class="kw">parent.frame</span>())</a>
<a class="sourceLine" id="cb4-15" data-line-number="15"> <span class="dv">1</span><span class="op">:</span><span class="st"> </span><span class="kw">lm</span>(pets <span class="op">~</span><span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">5</span>)</a></code></pre></div>
</section></section>
<section><section id="rstudio-features-can-help" class="title-slide slide level1"><h1>RStudio features can help</h1></section><section id="tab-completion" class="slide level2">
<h2>TAB completion</h2>
<p>Hit <code>TAB</code> key after typing the first few letters.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="kw">lm</span>(reallystrangenme<span class="op">~</span>anothrstrngenme)</a></code></pre></div>
</section><section id="find" class="slide level2">
<h2>“Find”</h2>
<p>Or use ctrl-F to ‘find’ variables with the same name. <img data-src="img/run_find.png" /></p>
</section><section id="rename-in-scope" class="slide level2">
<h2>Rename in Scope</h2>
<p>Rename all instances of a variable. Tool is context aware; changing ’m’ to ‘m1’ won’t change ‘mtcars’ to ‘m1tcars’.</p>
<p><img data-src="img/tip_rename_in_scope.gif" /></p>
</section><section id="command-history" class="slide level2">
<h2>Command History</h2>
<p>Scroll through the command history by clicking Ctrl/Cmd and ↑, then filter by typing.</p>
<p><img data-src="img/tip_console.gif" /></p>
</section><section id="history-pane" class="slide level2">
<h2>History Pane</h2>
<p>Searchable list of past commands. Commands can be written to the source pane or the console.</p>
<p><img data-src="img/tip_history.gif" /></p>
</section><section id="file-navigation" class="slide level2">
<h2>File Navigation</h2>
<p>Tab complete can find files and remove the hassle of writing out long path locations. Hit tab in between two double quotes (” “) to open a file explorer.</p>
<p><img data-src="img/tip_file_nav.gif" /></p>
</section><section id="debugging" class="slide level2">
<h2>Debugging</h2>
<p><a href="https://support.rstudio.com/hc/en-us/articles/205612627-Debugging-with-RStudio">Debugging in RStudio</a></p>
<ol type="1">
<li>Begin running the code</li>
<li>Stop the code at the point where you suspect the problem is arising, and</li>
<li>Look at and/or walk through the code, step-by-step at that point.</li>
</ol>
</section></section>
<section><section id="building-a-workflow" class="title-slide slide level1"><h1>Building a workflow</h1></section><section id="grandmas-recipe-book" class="slide level2">
<h2>Grandma’s Recipe Book</h2>
<ul>
<li class="fragment">Grandma writes the recipe for our favorite chocolate chip cookies</li>
<li class="fragment">We make a batch and they come out awful!</li>
<li class="fragment">Grandma makes another batch and they are delicious!</li>
<li class="fragment">Grandma says, “Well you didn’t add the sugar, of course you need about 2 cups of sugar!”</li>
<li class="fragment">No sugar in the recipe!</li>
<li class="fragment">Always, always, always think about the ‘flow’ of the script.</li>
</ul>
</section><section id="your-script-is-your-product" class="slide level2">
<h2>Your script is your product</h2>
</section><section id="it-worked-before-but-now-it-doesnt" class="slide level2">
<h2>“It worked before, but now it doesn’t”</h2>
<p>Possible explanations:</p>
<ul>
<li>Running commands in a different order</li>
<li>Skipping commands</li>
<li>Missing/incorrect/conflicts with packages</li>
<li>Different objects in environment (playing on the console?)</li>
</ul>
</section><section class="slide level2">
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="kw">library</span>(spData); <span class="kw">library</span>(rasterVis)</a>
<a class="sourceLine" id="cb6-2" data-line-number="2"><span class="kw">data</span>(elev)</a>
<a class="sourceLine" id="cb6-3" data-line-number="3"><span class="co"># change values!=20 to NA</span></a>
<a class="sourceLine" id="cb6-4" data-line-number="4">elev=<span class="kw">mask</span>(elev,<span class="dt">mask =</span> elev<span class="op">==</span><span class="dv">20</span>, <span class="dt">maskvalue=</span><span class="dv">0</span>) </a>
<a class="sourceLine" id="cb6-5" data-line-number="5"><span class="kw">gplot</span>(elev)<span class="op">+</span><span class="kw">geom_raster</span>(<span class="kw">aes</span>(<span class="dt">fill=</span>value))</a></code></pre></div>
<p><img data-src="PS_07_help_files/figure-revealjs/unnamed-chunk-9-1.png" /></p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">distance_to_<span class="dv">20</span>=<span class="kw">distance</span>(elev) <span class="co">#works fine</span></a>
<a class="sourceLine" id="cb7-2" data-line-number="2"><span class="kw">data</span>(elev)</a>
<a class="sourceLine" id="cb7-3" data-line-number="3"><span class="kw">gplot</span>(distance_to_<span class="dv">20</span>)<span class="op">+</span><span class="st"> </span><span class="kw">geom_raster</span>(<span class="kw">aes</span>(<span class="dt">fill=</span>value))</a></code></pre></div>
<p><img data-src="PS_07_help_files/figure-revealjs/unnamed-chunk-9-2.png" /></p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1">distance_to_<span class="dv">20</span>=<span class="kw">distance</span>(elev) <span class="co">#returns an error:</span></a>
<a class="sourceLine" id="cb8-2" data-line-number="2">Error <span class="cf">in</span> <span class="kw">.local</span>(x, y, ...) <span class="op">:</span><span class="st"> </span></a>
<a class="sourceLine" id="cb8-3" data-line-number="3">RasterLayer has no <span class="ot">NA</span> <span class="kw">cells</span> (<span class="cf">for</span> which to compute a distance)</a></code></pre></div>
</section><section id="goals-while-coding" class="slide level2">
<h2>Goals while coding</h2>
<ol type="1">
<li>Figure out how to complete your task</li>
<li>Build the script that will do it again (and again)</li>
</ol>
</section><section id="suggestions-for-building-clean-scripts" class="slide level2">
<h2>Suggestions for building clean scripts</h2>
<ol type="1">
<li>Try to keep your script ‘clean’ - it should always run from beginning to end</li>
<li>Comment exploratory lines such as <code>View(iris)</code>, <code>str(iris)</code>, etc.</li>
</ol>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1"><span class="co"># str(iris)</span></a></code></pre></div>
<ol start="3" type="1">
<li>If you want a little playground, try</li>
</ol>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" data-line-number="1"><span class="cf">if</span>(F){</a>
<a class="sourceLine" id="cb10-2" data-line-number="2"><span class="kw">View</span>(iris)</a>
<a class="sourceLine" id="cb10-3" data-line-number="3"><span class="kw">str</span>(iris)</a>
<a class="sourceLine" id="cb10-4" data-line-number="4">}</a></code></pre></div>
<ol start="4" type="1">
<li>Use the console (lower left) for testing, quick plots, temporary things.</li>
<li>Never do something important in the console without putting it in the script.</li>
</ol>
</section></section>
<section><section id="asking-for-help" class="title-slide slide level1"><h1>Asking for help</h1></section><section id="rs-community" class="slide level2">
<h2>R’s Community</h2>
<p>R has a large and generous community of users, help them help you.</p>
</section><section id="issue-posted-on-tidyrs-github-page" class="slide level2">
<h2>“Issue” posted on tidyr’s github page:</h2>
<p><a href="https://github.com/tidyverse/tidyr/issues/297">Separate() causes R to crash with fatal error</a> I have 11 primary variables, each one appears in the dataset in 72 columns: once for each month, for 6 years. Each variable name ends in “.YYYY_M”, where YYYY is a 4-digit year and M is month.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" data-line-number="1"><span class="op">></span><span class="st"> </span>vnms <-<span class="st"> </span><span class="kw">names</span>(outs_TN_wide)</a>
<a class="sourceLine" id="cb11-2" data-line-number="2"><span class="op">></span><span class="st"> </span>vars_tv <-<span class="st"> </span><span class="kw">grepl</span>(<span class="st">"20[01]</span><span class="ch">\\</span><span class="st">d"</span>, vnms)</a>
<a class="sourceLine" id="cb11-3" data-line-number="3"></a>
<a class="sourceLine" id="cb11-4" data-line-number="4"><span class="op">></span><span class="st"> </span>outs_TN_long <-<span class="st"> </span>outs_TN_wide <span class="op">%>%</span></a>
<a class="sourceLine" id="cb11-5" data-line-number="5"><span class="st"> </span><span class="kw">gather</span>(Variable, Value, <span class="kw">one_of</span>(vnms[vars_tv])) <span class="op">%>%</span></a>
<a class="sourceLine" id="cb11-6" data-line-number="6"><span class="st"> </span><span class="kw">separate</span>(Variable, <span class="kw">c</span>(<span class="st">"Variable"</span>, <span class="st">"Time"</span>), <span class="dt">sep =</span> <span class="st">"</span><span class="ch">\\</span><span class="st">."</span>)</a>
<a class="sourceLine" id="cb11-7" data-line-number="7"></a>
<a class="sourceLine" id="cb11-8" data-line-number="8">R encountered a fatal error.<span class="op">/</span>The session was terminated.</a></code></pre></div>
</section><section id="jun-23-2017-hadley-replies" class="slide level2">
<h2>Jun 23, 2017 <span class="citation" data-cites="hadley">@hadley</span> replies</h2>
<p>“Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you! If you’ve never heard of a reprex before, start by reading <a href="http://reprex.tidyverse.org/articles/reprex.html">"What is a reprex"</a>…”</p>
<p><img data-src="https://nypdecider.files.wordpress.com/2014/08/help-me-help-you.gif" /></p>
</section><section id="nov-14-2017-hadley-closes-this-issue" class="slide level2">
<h2>Nov 14, 2017 <span class="citation" data-cites="hadley">@hadley</span> closes this issue</h2>
<p>I’ve closed this issue due to lack of requested reprex. If you still care about this bug, please open a new issue with a reprex.</p>
<h3 id="the-more-helpful-you-are-the-more-likely-you-will-get-help.">The more helpful you are, the more likely you will get help.</h3>
</section><section id="build-a-reproducible-example-reprex" class="slide level2">
<h2>Build a Reproducible Example (REPREX)</h2>
<p>Break the problem down to the simplest possible illustation (preferably using built-in datasets).</p>
</section><section id="reprex-package" class="slide level2">
<h2>REPREX package</h2>
<p>Write a bit of code and copy it to the clipboard:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1">(y <-<span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">4</span>)</a>
<a class="sourceLine" id="cb12-2" data-line-number="2"><span class="kw">mean</span>(y)</a></code></pre></div>
<p>Type <code>reprex()</code> in the R Console. In RStudio, you’ll see a preview of your rendered reprex:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" data-line-number="1">(y <-<span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">4</span>)</a>
<a class="sourceLine" id="cb13-2" data-line-number="2"><span class="co">#> [1] 1 2 3 4</span></a>
<a class="sourceLine" id="cb13-3" data-line-number="3"><span class="kw">mean</span>(y)</a>
<a class="sourceLine" id="cb13-4" data-line-number="4"><span class="co">#> [1] 2.5</span></a></code></pre></div>
<p>Paste it into GitHub issue, StackOverflow, email, etc.</p>
</section><section id="this-is-a-lot-of-work" class="slide level2">
<h2>This is a lot of work!</h2>
<p>Yes! You are asking other people to do work too. It’s a partnership.</p>
<ul>
<li>You will often solve your own problem while developing the reprex!</li>
<li>If you don’t, you will create a reprex that will help others help you!</li>
</ul>
</section><section id="general-questions-stack-overflow" class="slide level2">
<h2>General Questions: Stack Overflow</h2>
<p><a href="https://stackoverflow.com/questions/tagged/r">R topics</a></p>
</section><section id="specific-bug-feature-request" class="slide level2">
<h2>Specific Bug / Feature Request</h2>
<p>Github “Issues” <a href="https://github.com/tidyverse/tidyr/issues" class="uri">https://github.com/tidyverse/tidyr/issues</a></p>
</section></section>
</div>
</div>
<script src="externals/reveal.js-3.3.0.1/lib/js/head.min.js"></script>
<script src="externals/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({
// Display the page number of the current slide
slideNumber: true,
// Push each slide change to the browser history
history: true,
// Vertical centering of slides
center: false,
// Enable slide navigation via mouse wheel
mouseWheel: true,
// Opens links in an iframe preview overlay
previewLinks: true,
// Transition style
transition: 'zoom', // none/fade/slide/convex/concave/zoom
// Transition style for full page slide backgrounds
backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom
// The "normal" size of the presentation, aspect ratio will be preserved
// when the presentation is scaled to fit different resolutions. Can be
// specified using percentage units.
width: '90%',
height: '100%',
// Factor of the display size that should remain empty around the content
margin: 0.1,
// Bounds for smallest/largest possible scale to apply to content
minScale: 1,
maxScale: 3,
chalkboard: {
},
keyboard: {
67: function() { RevealChalkboard.toggleNotesCanvas() }, // toggle notes canvas when 'c' is pressed
66: function() { RevealChalkboard.toggleChalkboard() }, // toggle chalkboard when 'b' is pressed
46: function() { RevealChalkboard.clear() }, // clear chalkboard when 'DEL' is pressed
8: function() { RevealChalkboard.reset() }, // reset chalkboard data on current slide when 'BACKSPACE' is pressed
68: function() { RevealChalkboard.download() }, // downlad recorded chalkboard drawing when 'd' is pressed
},
// Optional reveal.js plugins
dependencies: [
{ src: 'externals/reveal.js-3.3.0.1/plugin/zoom-js/zoom.js', async: true },
{ src: 'externals/reveal.js-3.3.0.1/plugin/chalkboard/chalkboard.js', async: true },
]
});
</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>