1<!DOCTYPE html> 2<html lang="en"><head>
3<script src="index_files/libs/clipboard/clipboard.min.js"></script>
vendor: 1 bytes, line 3
3
4<script src="index_files/libs/quarto-html/tabby.min.js"></script>
vendor: 1 bytes, line 4
4
5<script src="index_files/libs/quarto-html/popper.min.js"></script>
vendor: 1 bytes, line 5
5
6<script src="index_files/libs/quarto-html/tippy.umd.min.js"></script>
6 7<link href="index_files/libs/quarto-html/tippy.css" rel="stylesheet"> 8<link href="index_files/libs/quarto-html/light-border.css" rel="stylesheet"> 9<link href="index_files/libs/quarto-html/quarto-syntax-highlighting-ea385d0e468b0dd5ea5bf0780b1290d9.css" rel="stylesheet" id="quarto-text-highlighting-styles">
10<script src="index_files/libs/quarto-contrib/glightbox/glightbox.min.js"></script>
10 11<link href="index_files/libs/quarto-contrib/glightbox/glightbox.min.css" rel="stylesheet"> 12<link href="index_files/libs/quarto-contrib/glightbox/lightbox.css" rel="stylesheet"><meta charset="utf-8"> 13 <meta name="generator" content="quarto-1.7.33"> 14 15 <meta name="author" content="Sakeef M. Karim Amherst College AN INTRODUCTION TO QUANTITATIVE SOCIOLOGYâCULTURE & POWER"> 16 <title>Lecture 6 for SOCIâ269 at Amherst College</title> 17 <meta name="apple-mobile-web-app-capable" content="yes"> 18 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> 19 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"> 20 <link rel="stylesheet" href="index_files/libs/revealjs/dist/reset.css"> 21 <link rel="stylesheet" href="index_files/libs/revealjs/dist/reveal.css"> 22 <style> 23 code{white-space: pre-wrap;} 24 span.smallcaps{font-variant: small-caps;} 25 div.columns{display: flex; gap: min(4vw, 1.5em);} 26 div.column{flex: auto; overflow-x: auto;} 27 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} 28 ul.task-list{list-style: none;} 29 ul.task-list li input[type="checkbox"] { 30 width: 0.8em; 31 margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 32 vertical-align: middle; 33 } 34 /* CSS for syntax highlighting */ 35 html { -webkit-text-size-adjust: 100%; } 36 pre > code.sourceCode { white-space: pre; position: relative; } 37 pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } 38 pre > code.sourceCode > span:empty { height: 1.2em; } 39 .sourceCode { overflow: visible; } 40 code.sourceCode > span { color: inherit; text-decoration: inherit; } 41 div.sourceCode { margin: 1em 0; } 42 pre.sourceCode { margin: 0; } 43 @media screen { 44 div.sourceCode { overflow: auto; } 45 } 46 @media print { 47 pre > code.sourceCode { white-space: pre-wrap; } 48 pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } 49 } 50 pre.numberSource code 51 { counter-reset: source-line 0; } 52 pre.numberSource code > span 53 { position: relative; left: -4em; counter-increment: source-line; } 54 pre.numberSource code > span > a:first-child::before 55 { content: counter(source-line); 56 position: relative; left: -1em; text-align: right; vertical-align: baseline; 57 border: none; display: inline-block; 58 -webkit-touch-callout: none; -webkit-user-select: none; 59 -khtml-user-select: none; -moz-user-select: none; 60 -ms-user-select: none; user-select: none; 61 padding: 0 4px; width: 4em; 62 color: #aaaaaa; 63 } 64 pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } 65 div.sourceCode 66 { color: #003b4f; background-color: #f1f3f5; } 67 @media screen { 68 pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } 69 } 70 code span { color: #003b4f; } /* Normal */ 71 code span.al { color: #ad0000; } /* Alert */ 72 code span.an { color: #5e5e5e; } /* Annotation */ 73 code span.at { color: #657422; } /* Attribute */ 74 code span.bn { color: #ad0000; } /* BaseN */ 75 code span.bu { } /* BuiltIn */ 76 code span.cf { color: #003b4f; font-weight: bold; } /* ControlFlow */ 77 code span.ch { color: #20794d; } /* Char */ 78 code span.cn { color: #8f5902; } /* Constant */ 79 code span.co { color: #5e5e5e; } /* Comment */ 80 code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */ 81 code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */ 82 code span.dt { color: #ad0000; } /* DataType */ 83 code span.dv { color: #ad0000; } /* DecVal */ 84 code span.er { color: #ad0000; } /* Error */ 85 code span.ex { } /* Extension */ 86 code span.fl { color: #ad0000; } /* Float */ 87 code span.fu { color: #4758ab; } /* Function */ 88 code span.im { color: #00769e; } /* Import */ 89 code span.in { color: #5e5e5e; } /* Information */ 90 code span.kw { color: #003b4f; font-weight: bold; } /* Keyword */ 91 code span.op { color: #5e5e5e; } /* Operator */ 92 code span.ot { color: #003b4f; } /* Other */ 93 code span.pp { color: #ad0000; } /* Preprocessor */ 94 code span.sc { color: #5e5e5e; } /* SpecialChar */ 95 code span.ss { color: #20794d; } /* SpecialString */ 96 code span.st { color: #20794d; } /* String */ 97 code span.va { color: #111111; } /* Variable */ 98 code span.vs { color: #20794d; } /* VerbatimString */ 99 code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */ 100 /* CSS for citations */ 101 div.csl-bib-body { } 102 div.csl-entry { 103 clear: both; 104 } 105 .hanging-indent div.csl-entry { 106 margin-left:2em; 107 text-indent:-2em; 108 } 109 div.csl-left-margin { 110 min-width:2em; 111 float:left; 112 } 113 div.csl-right-inline { 114 margin-left:2em; 115 padding-left:1em; 116 } 117 div.csl-indent { 118 margin-left: 2em; 119 } </style> 120 <link rel="stylesheet" href="index_files/libs/revealjs/dist/theme/quarto-90b34bde85941f939ab6b23afa7c1215.css"> 121 <link rel="stylesheet" href="logo.css"> 122
122<script>window.backupDefine = window.define; window.define = undefined;</script>
122<script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
122 123
123<script>document.addEventListener("DOMContentLoaded", function () { 124 var mathElements = document.getElementsByClassName("math"); 125 var macros = []; 126 for (var i = 0; i < mathElements.length; i++) { 127 var texText = mathElements[i].firstChild; 128 if (mathElements[i].tagName == "SPAN") { 129 katex.render(texText.data, mathElements[i], { 130 displayMode: mathElements[i].classList.contains('display'), 131 throwOnError: false, 132 macros: macros, 133 fleqn: false 134 }); 135}}}); 136 </script>
136 137
137<script>window.define = window.backupDefine; window.backupDefine = undefined;</script>
137<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css"> 138 <link href="index_files/libs/revealjs/plugin/quarto-line-highlight/line-highlight.css" rel="stylesheet"> 139 <link href="index_files/libs/revealjs/plugin/reveal-menu/menu.css" rel="stylesheet"> 140 <link href="index_files/libs/revealjs/plugin/reveal-menu/quarto-menu.css" rel="stylesheet"> 141 <link href="index_files/libs/revealjs/plugin/reveal-chalkboard/font-awesome/css/all.css" rel="stylesheet"> 142 <link href="index_files/libs/revealjs/plugin/reveal-chalkboard/style.css" rel="stylesheet"> 143 <link href="index_files/libs/revealjs/plugin/reveal-attribution/attribution.css" rel="stylesheet"> 144 <link href="index_files/libs/revealjs/plugin/simplemenu/simplemenu.css" rel="stylesheet"> 145 <link href="index_files/libs/revealjs/plugin/quarto-support/footer.css" rel="stylesheet"> 146 <style type="text/css"> 147 .reveal div.sourceCode { 148 margin: 0; 149 overflow: auto; 150 } 151 .reveal div.hanging-indent { 152 margin-left: 1em; 153 text-indent: -1em; 154 } 155 .reveal .slide:not(.center) { 156 height: 100%; 157 overflow-y: auto; 158 } 159 .reveal .slide.scrollable { 160 overflow-y: auto; 161 } 162 .reveal .footnotes { 163 height: 100%; 164 overflow-y: auto; 165 } 166 .reveal .slide .absolute { 167 position: absolute; 168 display: block; 169 } 170 .reveal .footnotes ol { 171 counter-reset: ol; 172 list-style-type: none; 173 margin-left: 0; 174 } 175 .reveal .footnotes ol li:before { 176 counter-increment: ol; 177 content: counter(ol) ". "; 178 } 179 .reveal .footnotes ol li > p:first-child { 180 display: inline-block; 181 } 182 .reveal .slide ul, 183 .reveal .slide ol { 184 margin-bottom: 0.5em; 185 } 186 .reveal .slide ul li, 187 .reveal .slide ol li { 188 margin-top: 0.4em; 189 margin-bottom: 0.2em; 190 } 191 .reveal .slide ul[role="tablist"] li { 192 margin-bottom: 0; 193 } 194 .reveal .slide ul li > *:first-child, 195 .reveal .slide ol li > *:first-child { 196 margin-block-start: 0; 197 } 198 .reveal .slide ul li > *:last-child, 199 .reveal .slide ol li > *:last-child { 200 margin-block-end: 0; 201 } 202 .reveal .slide .columns:nth-child(3) { 203 margin-block-start: 0.8em; 204 } 205 .reveal blockquote { 206 box-shadow: none; 207 } 208 .reveal .tippy-content>* { 209 margin-top: 0.2em; 210 margin-bottom: 0.7em; 211 } 212 .reveal .tippy-content>*:last-child { 213 margin-bottom: 0.2em; 214 } 215 .reveal .slide > img.stretch.quarto-figure-center, 216 .reveal .slide > img.r-stretch.quarto-figure-center { 217 display: block; 218 margin-left: auto; 219 margin-right: auto; 220 } 221 .reveal .slide > img.stretch.quarto-figure-left, 222 .reveal .slide > img.r-stretch.quarto-figure-left { 223 display: block; 224 margin-left: 0; 225 margin-right: auto; 226 } 227 .reveal .slide > img.stretch.quarto-figure-right, 228 .reveal .slide > img.r-stretch.quarto-figure-right { 229 display: block; 230 margin-left: auto; 231 margin-right: 0; 232 } 233 </style> 234
234<script src="index_files/libs/core-js-2.5.3/shim.min.js"></script>
234 235
235<script src="index_files/libs/react-18.2.0/react.min.js"></script>
235 236
236<script src="index_files/libs/react-18.2.0/react-dom.min.js"></script>
236 237
237<script src="index_files/libs/reactwidget-2.0.0/react-tools.js"></script>
237 238 <link href="index_files/libs/htmltools-fill-0.5.8.1/fill.css" rel="stylesheet"> 239
239<script src="index_files/libs/htmlwidgets-1.6.4/htmlwidgets.js"></script>
239 240 <link href="index_files/libs/reactable-0.4.4/reactable.css" rel="stylesheet"> 241
241<script src="index_files/libs/reactable-binding-0.4.4/reactable.js"></script>
241 242 <link rel="icon" type="media/png" href="media/line-chart.png"> 243 <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> 244 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/editor/editor.main.css"> 245 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"> 246 247 <style type="text/css"> 248 .monaco-editor pre { 249 background-color: unset !important; 250 } 251 252 .qwebr-editor-toolbar { 253 width: 100%; 254 display: flex; 255 justify-content: space-between; 256 box-sizing: border-box; 257 } 258 259 .qwebr-editor-toolbar-left-buttons, .qwebr-editor-toolbar-right-buttons { 260 display: flex; 261 } 262 263 .qwebr-non-interactive-loading-container.qwebr-cell-needs-evaluation, .qwebr-non-interactive-loading-container.qwebr-cell-evaluated { 264 justify-content: center; 265 display: flex; 266 background-color: rgba(250, 250, 250, 0.65); 267 border: 1px solid rgba(233, 236, 239, 0.65); 268 border-radius: 0.5rem; 269 margin-top: 15px; 270 margin-bottom: 15px; 271 } 272 273 .qwebr-r-project-logo { 274 color: #2767B0; /* R Project's blue color */ 275 } 276 277 .qwebr-icon-status-spinner { 278 color: #7894c4; 279 } 280 281 .qwebr-icon-run-code { 282 color: #0d9c29 283 } 284 285 body.quarto-light .qwebr-output-code-stdout { 286 color: #111; 287 } 288 289 body.quarto-dark .qwebr-output-code-stdout { 290 color: #EEE; 291 } 292 293 .qwebr-output-code-stderr { 294 color: #db4133; 295 } 296 297 body.quarto-light .qwebr-editor { 298 border: 1px solid #EEEEEE; 299 } 300 301 body.quarto-light .qwebr-editor-toolbar { 302 background-color: #EEEEEE; 303 padding: 0.2rem 0.5rem; 304 } 305 306 body.quarto-dark .qwebr-editor { 307 border: 1px solid #111; 308 } 309 310 body.quarto-dark .qwebr-editor-toolbar { 311 background-color: #111; 312 padding: 0.2rem 0.5rem; 313 } 314 315 .qwebr-button { 316 display: inline-block; 317 font-weight: 400; 318 line-height: 1; 319 text-decoration: none; 320 text-align: center; 321 padding: 0.375rem 0.75rem; 322 font-size: .9rem; 323 border-radius: 0.25rem; 324 transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; 325 } 326 327 body.quarto-light .qwebr-button { 328 background-color: #EEEEEE; 329 color: #000; 330 border-color: #dee2e6; 331 border: 1px solid rgba(0,0,0,0); 332 } 333 334 body.quarto-dark .qwebr-button { 335 background-color: #111; 336 color: #EEE; 337 border-color: #dee2e6; 338 border: 1px solid rgba(0,0,0,0); 339 } 340 341 body.quarto-light .qwebr-button:hover { 342 color: #000; 343 background-color: #d9dce0; 344 border-color: #c8ccd0; 345 } 346 347 body.quarto-dark .qwebr-button:hover { 348 color: #d9dce0; 349 background-color: #323232; 350 border-color: #d9dce0; 351 } 352 353 .qwebr-button:disabled,.qwebr-button.disabled,fieldset:disabled .qwebr-button { 354 pointer-events: none; 355 opacity: .65 356 } 357 358 .qwebr-button-reset { 359 color: #696969; /*#4682b4;*/ 360 } 361 362 .qwebr-button-copy { 363 color: #696969; 364 } 365 366 /* Style the code highlight lines */ 367 body.quarto-light .qwebr-editor-highlight-line { 368 background-color: lightblue; 369 } 370 371 body.quarto-dark .qwebr-editor-highlight-line { 372 background-color: darkblue; 373 } 374 375 /* Style the modal pop-up */ 376 377 /* The Modal (background) */ 378 .qwebr-modal { 379 display: none; /* Hidden by default */ 380 position: fixed; /* Stay in place */ 381 z-index: 1; /* Sit on top */ 382 left: 0; 383 top: 0; 384 width: 100%; /* Full width */ 385 height: 100%; /* Full height */ 386 overflow: auto; /* Enable scroll if needed */ 387 background-color: rgb(0,0,0); /* Fallback color */ 388 background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ 389 padding-top: 60px; 390 } 391 392 /* Modal Content */ 393 .qwebr-modal-content { 394 background-color: #fefefe; 395 margin: 5% auto; /* 15% from the top and centered */ 396 padding: 20px; 397 border: 1px solid #888; 398 width: 80%; /* Could be more or less, depending on screen size */ 399 } 400 401 .qwebr-modal-content-code { 402 max-height: 50vh; 403 min-height: 5vh; 404 overflow: scroll; 405 border: 1px solid #888; 406 } 407 408 /* The Close Button */ 409 .qwebr-modal-close { 410 color: #aaa; 411 float: right; 412 font-size: 28px; 413 font-weight: bold; 414 } 415
416 .qwebr-modal-close:hover, 417 .qwebr-modal-close:focus { 418 color: black; 419 text-decoration: none; 420 cursor: pointer; 421 } 422 423 .qwebr-download-btn { 424 margin-top: 10px; 425 text-decoration: none !important; 426 } 427 428 /* Styling to download image that is created */ 429 430 .qwebr-canvas-image { 431 position: relative; 432 display: inline-block; 433 margin: 10px; 434 } 435 436 .qwebr-canvas-image-download-btn { 437 position: absolute; 438 top: 10px; 439 right: 10px; 440 padding: 5px 10px; 441 background-color: #007BFF; 442 color: white; 443 border: none; 444 cursor: pointer; 445 display: none; 446 } 447 448 figure:hover .qwebr-canvas-image-download-btn { 449 display: block; 450 } 451 452 /* Custom styling for RevealJS Presentations*/ 453 454 /* Reset the style of the interactive area */ 455 .reveal div.qwebr-interactive-area { 456 display: block; 457 box-shadow: none; 458 max-width: 100%; 459 max-height: 100%; 460 margin: 0; 461 padding: 0; 462 } 463 464 /* Provide space to entries */ 465 .reveal div.qwebr-output-code-area pre div { 466 margin: 1px 2px 1px 10px; 467 } 468 469 /* Collapse the inside code tags to avoid extra space between line outputs */ 470 .reveal pre div code.qwebr-output-code-stdout, .reveal pre div code.qwebr-output-code-stderr { 471 padding: 0; 472 display: contents; 473 } 474 475 body.reveal.quarto-light pre div code.qwebr-output-code-stdout { 476 color: #111; 477 } 478 479 body.reveal.quarto-dark pre div code.qwebr-output-code-stdout { 480 color: #EEEEEE; 481 } 482 483 .reveal pre div code.qwebr-output-code-stderr { 484 color: #db4133; 485 } 486 487 488 /* Create a border around console and output (does not effect graphs) */ 489 body.reveal.quarto-light div.qwebr-console-area { 490 border: 1px solid #EEEEEE; 491 box-shadow: 2px 2px 10px #EEEEEE; 492 } 493 494 body.reveal.quarto-dark div.qwebr-console-area { 495 border: 1px solid #111; 496 box-shadow: 2px 2px 10px #111; 497 } 498 499 500 /* Cap output height and allow text to scroll */ 501 /* TODO: Is there a better way to fit contents/max it parallel to the monaco editor size? */ 502 .reveal div.qwebr-output-code-area pre { 503 max-height: 400px; 504 overflow: scroll; 505 } 506 507 iframe.qwebr-output-code-browse { 508 width: 100%; 509 510 /* 511 TODO: How to make the height automatic according to the widget size, 512 or respect the quarto code block options? 513 */ 514 min-height: 500px; 515 } 516 517 </style> 518
518<script type="module"> 519 // Document level settings ---- 520 521 // Determine if we need to install R packages 522 globalThis.qwebrInstallRPackagesList = ['tidyverse', 'nycflights13', 'gapminder', 'palmerpenguins']; 523 524 // Specify possible locations to search for the repository 525 globalThis.qwebrPackageRepoURLS = ['https://repo.r-wasm.org/']; 526 527 // Check to see if we have an empty array, if we do set to skip the installation. 528 globalThis.qwebrSetupRPackages = !(qwebrInstallRPackagesList.indexOf("") !== -1); 529 globalThis.qwebrAutoloadRPackages = true; 530 531 // Display a startup message? 532 globalThis.qwebrShowStartupMessage = false; 533 globalThis.qwebrShowHeaderMessage = false; 534 535 // Describe the webR settings that should be used 536 globalThis.qwebrCustomizedWebROptions = { 537 "baseURL": "https://webr.r-wasm.org/v0.5.2/", 538 "serviceWorkerUrl": "", 539 "homedir": "/home/web_user", 540 "channelType": "ChannelType.Automatic" 541 }; 542 543 // Store cell data 544 globalThis.qwebrCellDetails = [{"code":"(1 / 500) + 34","id":1,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-1","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"c(\"Amherst College\", \"Hampshire College\", \"Mount Holyoke College\", \"Smith College\",\n \"University of Massachusetts at Amherst\")","id":2,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-2","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"c(1:3, 4:0)","id":3,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-3","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"x <- c(1, 2, 3)","id":4,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-4","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"c(\"Amherst College\", \"Hampshire College\", \"Mount Holyoke College\", \"Smith College\", \"University of Massachusetts at Amherst\")","id":5,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-5","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"5colleges <- c(\"Amherst College\", \"Hampshire College\", \"Mount Holyoke College\", \"Smith College\", \"University of Massachusetts at Amherst\")","id":6,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-6","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"iris","id":7,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-7","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"min(iris$Sepal.Width)","id":8,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-8","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"# Finding the minimum value of the Sepal.Width variable\n\nmin(iris$Sepal.Width)","id":9,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-9","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"# install.packages(\"palmerpenguins\")\n\nlibrary(palmerpenguins)\n\npenguins","id":10,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-10","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"flights |> # Isolate United Airlines\n filter(carrier == \"UA\") |> \n # Zoom-in on variables of interest\n select(month, day, carrier, flight, origin) |> \n # Change \"month\" variable from integer to character label:\n mutate(month = lubridate::month(month, label = TRUE, abbr = FALSE)) |> \n # Create a new flight number variable by unifying \"carrier\" and \"flight\" variables:\n tidyr::unite(\"flight_number\", carrier, flight, sep = \" \") |> \n # Grouping by airport of origin/counting frequency --- ensuring df is ungrouped:\n with_groups(origin, count, flight_number, sort = TRUE) |>
544 \n # Top 2 counts\n slice_head(n = 2)","id":11,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-11","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> filter(country == \"Canada\")","id":12,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-12","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> filter(year == min(year),\n lifeExp >= 70)","id":13,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-13","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> filter(year == min(year),\n str_detect(country, \"Indo\"))","id":14,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-14","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> arrange(continent)","id":15,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-15","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> arrange(continent, pop)","id":16,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-16","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> arrange(desc(continent), -gdpPercap)","id":17,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-17","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> distinct(species)","id":18,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-18","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> distinct(species, island)","id":19,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-19","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> select(species, sex, bill_length_mm) |> \n distinct()","id":20,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-20","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"# A new variable for the log of population:\n\ngapminder |> mutate(l_pop = log(pop),\n .after = pop)","id":21,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-21","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"# Creating an indicator variable for Africa:\n\ngapminder |> mutate(africa = ifelse(str_detect(continent, \"Afr\"), 1, 0)) |> \n filter(africa == 1)","id":22,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-22","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> select(country, 3, population = pop)","id":23,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-23","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"flights |> select(contains(\"dep\"), starts_with(\"tail\"))","id":24,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-24","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"# Here's how we would select the first three columns:\n\npenguins |> select(1:3)","id":25,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-25","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> rename(life_expectancy = lifeExp)","id":26,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-26","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> rename(life_expectancy = 4)","id":27,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-27","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> relocate(sex, year)","id":28,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-28","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> relocate(sex, year, .after = island)","id":29,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-29","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> relocate(contains(\"bill_\"), .after = last_col())","id":30,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-30","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> group_by(lifeExp)","id":31,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-31","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> group_by(continent, year)","id":32,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-32","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"penguins |> group_by(species) |> \n summarize(bill_length_10 = quantile(bill_length_mm, probs = 0.10))","id":33,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-33","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> group_by(continent, year) |>
544 \n summarize(avg_lexp = mean(lifeExp), .groups = \"keep\") ","id":34,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-34","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> summarize(avg_lexp = mean(lifeExp),\n .by = c(continent, year))","id":35,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-35","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> group_by(continent) |>\n slice_head(n = 2) \n # slice_tail(n = 2)","id":36,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-36","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"gapminder |> group_by(continent, year) |>\n slice_min(lifeExp, n = 1) \n # slice_max(lifeExp, n = 2)","id":37,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-37","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}},{"code":"# set.seed(905)\ngapminder |> slice_sample(prop = 0.05, by = continent) ","id":38,"options":{"autorun":"false","classes":"","comment":"","context":"interactive","dpi":72,"editor-font-scale":"0.5","editor-max-height":"","editor-quick-suggestions":"false","editor-word-wrap":"true","fig-cap":"","fig-height":5,"fig-width":7,"label":"unnamed-chunk-38","message":"true","out-height":"","out-width":"700px","output":"true","read-only":"false","results":"markup","warning":"true"}}]; 545 546 </script>
546 547
547<script type="module"> 548 // Declare startupMessageQWebR globally 549 globalThis.qwebrStartupMessage = document.createElement("p"); 550 551 // Verify if OffScreenCanvas is supported 552 globalThis.qwebrOffScreenCanvasSupport = function() { 553 return typeof OffscreenCanvas !== 'undefined' 554 } 555 556 // Function to set the button text 557 globalThis.qwebrSetInteractiveButtonState = function(buttonText, enableCodeButton = true) { 558 document.querySelectorAll(".qwebr-button-run").forEach((btn) => { 559 btn.innerHTML = buttonText; 560 btn.disabled = !enableCodeButton; 561 }); 562 } 563 564 // Function to update the status message in non-interactive cells 565 globalThis.qwebrUpdateStatusMessage = function(message) { 566 document.querySelectorAll(".qwebr-status-text.qwebr-cell-needs-evaluation").forEach((elem) => { 567 elem.innerText = message; 568 }); 569 } 570 571 // Function to update the status message 572 globalThis.qwebrUpdateStatusHeader = function(message) { 573 qwebrStartupMessage.innerHTML = ` 574 <i class="fa-solid fa-spinner fa-spin qwebr-icon-status-spinner"></i> 575 <span>${message}</span>`; 576 } 577 578 // Function to return true if element is found, false if not 579 globalThis.qwebrCheckHTMLElementExists = function(selector) { 580 const element = document.querySelector(selector); 581 return !!element; 582 } 583 584 // Function that detects whether reveal.js slides are present 585 globalThis.qwebrIsRevealJS = function() { 586 // If the '.reveal .slides' selector exists, RevealJS is likely present 587 return qwebrCheckHTMLElementExists('.reveal .slides'); 588 } 589 590 // Initialize the Quarto sidebar element 591 function qwebrSetupQuartoSidebar() { 592 var newSideBarDiv = document.createElement('div'); 593 newSideBarDiv.id = 'quarto-margin-sidebar'; 594 newSideBarDiv.className = 'sidebar margin-sidebar'; 595 newSideBarDiv.style.top = '0px'; 596 newSideBarDiv.style.maxHeight = 'calc(0px + 100vh)'; 597 598 return newSideBarDiv; 599 } 600 601 // Position the sidebar in the document 602 function qwebrPlaceQuartoSidebar() { 603 // Get the reference to the element with id 'quarto-document-content' 604 var referenceNode = document.getElementById('quarto-document-content'); 605 606 // Create the new div element 607 var newSideBarDiv = qwebrSetupQuartoSidebar(); 608 609 // Insert the new div before the 'quarto-document-content' element 610 referenceNode.parentNode.insertBefore(newSideBarDiv, referenceNode); 611 } 612 613 function qwebrPlaceMessageContents(content, html_location = "title-block-header", revealjs_location = "title-slide") { 614 615 // Get references to header elements 616 const headerHTML = document.getElementById(html_location); 617 const headerRevealJS = document.getElementById(revealjs_location); 618 619 // Determine where to insert the quartoTitleMeta element 620 if (headerHTML || headerRevealJS) { 621 // Append to the existing "title-block-header" element or "title-slide" div 622 (headerHTML || headerRevealJS).appendChild(content); 623 } else { 624 // If neither headerHTML nor headerRevealJS is found, insert after "webr-monaco-editor-init" script 625 const monacoScript = document.getElementById("qwebr-monaco-editor-init"); 626 const header = document.createElement("header"); 627 header.setAttribute("id", "title-block-header"); 628 header.appendChild(content); 629 monacoScript.after(header); 630 } 631 } 632 633 634 635 function qwebrOffScreenCanvasSupportWarningMessage() { 636 637 // Verify canvas is supported. 638 if(qwebrOffScreenCanvasSupport()) return; 639 640 // Create the main container div 641 var calloutContainer = document.createElement('div'); 642 calloutContainer.classList.add('callout', 'callout-style-default', 'callout-warning', 'callout-titled'); 643 644 // Create the header div 645 var headerDiv = document.createElement('div'); 646 headerDiv.classList.add('callout-header', 'd-flex', 'align-content-center'); 647 648 // Create the icon container div 649 var iconContainer = document.createElement('div'); 650 iconContainer.classList.add('callout-icon-container'); 651 652 // Create the icon element 653 var iconElement = document.createElement('i'); 654 iconElement.classList.add('callout-icon'); 655 656 // Append the icon element to the icon container 657 iconContainer.appendChild(iconElement); 658 659 // Create the title container div 660 var titleContainer = document.createElement('div'); 661 titleContainer.classList.add('callout-title-container', 'flex-fill'); 662 titleContainer.innerText = 'Warning: Web Browser Does Not Support Graphing!'; 663 664 // Append the icon container and title container to the header div 665 headerDiv.appendChild(iconContainer); 666 headerDiv.appendChild(titleContainer); 667 668 // Create the body container div 669 var bodyContainer = document.createElement('div'); 670 bodyContainer.classList.add('callout-body-container', 'callout-body'); 671 672 // Create the paragraph element for the body content 673 var paragraphElement = document.createElement('p'); 674 paragraphElement.innerHTML = 'This web browser does not have support for displaying graphs through the <code>quarto-webr</code> extension since it lacks an <code>OffScreenCanvas</code>. Please upgrade your web browser to one that supports <code>OffScreenCanvas</code>.'; 675 676 // Append the paragraph element to the body container 677 bodyContainer.appendChild(paragraphElement); 678 679 // Append the header div and body container to the main container div 680 calloutContainer.appendChild(headerDiv); 681 calloutContainer.appendChild(bodyContainer); 682 683 // Append the main container div to the document depending on format 684 qwebrPlaceMessageContents(calloutContainer, "title-block-header"); 685 686 } 687 688 689 // Function that attaches the document status message and diagnostics 690 function displayStartupMessage(showStartupMessage, showHeaderMessage) { 691 if (!showStartupMessage) { 692 return; 693 } 694 695 // Create the outermost div element for metadata 696 const quartoTitleMeta = document.createElement("div"); 697 quartoTitleMeta.classList.add("quarto-title-meta"); 698 699 // Create the first inner div element 700 const firstInnerDiv = document.createElement("div"); 701 firstInnerDiv.setAttribute("id", "qwebr-status-message-area"); 702 703 // Create the second inner div element for "WebR Status" heading and contents 704 const secondInnerDiv = document.createElement("div"); 705 secondInnerDiv.setAttribute("id", "qwebr-status-message-title"); 706 secondInnerDiv.classList.add("quarto-title-meta-heading"); 707 secondInnerDiv.innerText = "WebR Status"; 708 709 // Create another inner div for contents 710 const secondInnerDivContents = document.createElement("div"); 711 secondInnerDivContents.setAttribute("id", "qwebr-status-message-body"); 712 secondInnerDivContents.classList.add("quarto-title-meta-contents"); 713 714 // Describe the WebR state 715 qwebrStartupMessage.innerText = "ð¡ Loading..."; 716 qwebrStartupMessage.setAttribute("id", "qwebr-status-message-text"); 717 // Add `aria-live` to auto-announce the startup status to screen readers 718 qwebrStartupMessage.setAttribute("aria-live", "assertive"); 719 720 // Append the startup message to the contents 721 secondInnerDivContents.appendChild(qwebrStartupMessage); 722 723 // Add a status indicator for COOP and COEP Headers if needed 724 if (showHeaderMessage) { 725 const crossOriginMessage = document.createElement("p"); 726 crossOriginMessage.innerText = `${crossOriginIsolated ? 'ð¢' : 'ð¡'} COOP & COEP Headers`; 727 crossOriginMessage.setAttribute("id", "qwebr-coop-coep-header"); 728 secondInnerDivContents.appendChild(crossOriginMessage); 729 } 730 731 // Combine the inner divs and contents 732 firstInnerDiv.appendChild(secondInnerDiv); 733 firstInnerDiv.appendChild(secondInnerDivContents); 734 quartoTitleMeta.appendChild(firstInnerDiv); 735 736 // Place message on webpage
737 qwebrPlaceMessageContents(quartoTitleMeta); 738 } 739 740 function qwebrAddCommandHistoryModal() { 741 // Create the modal div 742 var modalDiv = document.createElement('div'); 743 modalDiv.id = 'qwebr-history-modal'; 744 modalDiv.className = 'qwebr-modal'; 745 746 // Create the modal content div 747 var modalContentDiv = document.createElement('div'); 748 modalContentDiv.className = 'qwebr-modal-content'; 749 750 // Create the span for closing the modal 751 var closeSpan = document.createElement('span'); 752 closeSpan.id = 'qwebr-command-history-close-btn'; 753 closeSpan.className = 'qwebr-modal-close'; 754 closeSpan.innerHTML = '×'; 755 756 // Create the h1 element for the modal 757 var modalH1 = document.createElement('h1'); 758 modalH1.textContent = 'R History Command Contents'; 759 760 // Create an anchor element for downloading the Rhistory file 761 var downloadLink = document.createElement('a'); 762 downloadLink.href = '#'; 763 downloadLink.id = 'qwebr-download-history-btn'; 764 downloadLink.className = 'qwebr-download-btn'; 765 766 // Create an 'i' element for the icon 767 var icon = document.createElement('i'); 768 icon.className = 'bi bi-file-code'; 769 770 // Append the icon to the anchor element 771 downloadLink.appendChild(icon); 772 773 // Add the text 'Download R History' to the anchor element 774 downloadLink.appendChild(document.createTextNode(' Download R History File')); 775 776 // Create the pre for command history contents 777 var commandContentsPre = document.createElement('pre'); 778 commandContentsPre.id = 'qwebr-command-history-contents'; 779 commandContentsPre.className = 'qwebr-modal-content-code'; 780 781 // Append the close span, h1, and history contents pre to the modal content div 782 modalContentDiv.appendChild(closeSpan); 783 modalContentDiv.appendChild(modalH1); 784 modalContentDiv.appendChild(downloadLink); 785 modalContentDiv.appendChild(commandContentsPre); 786 787 // Append the modal content div to the modal div 788 modalDiv.appendChild(modalContentDiv); 789 790 // Append the modal div to the body 791 document.body.appendChild(modalDiv); 792 } 793 794 function qwebrRegisterRevealJSCommandHistoryModal() { 795 // Select the <ul> element inside the <div> with data-panel="Custom0" 796 let ulElement = document.querySelector('div[data-panel="Custom0"] > ul.slide-menu-items'); 797 798 // Find the last <li> element with class slide-tool-item 799 let lastItem = ulElement.querySelector('li.slide-tool-item:last-child'); 800 801 // Calculate the next data-item value 802 let nextItemValue = 0; 803 if (lastItem) { 804 nextItemValue = parseInt(lastItem.dataset.item) + 1; 805 } 806 807 // Create a new <li> element 808 let newListItem = document.createElement('li'); 809 newListItem.className = 'slide-tool-item'; 810 newListItem.dataset.item = nextItemValue.toString(); // Set the next available data-item value 811 812 // Create the <a> element inside the <li> 813 let newLink = document.createElement('a'); 814 newLink.href = '#'; 815 newLink.id = 'qwebrRHistoryButton'; // Set the ID for the new link 816 817 // Create the <kbd> element inside the <a> 818 let newKbd = document.createElement('kbd'); 819 newKbd.textContent = ' '; // Set to empty as we are not registering a keyboard shortcut 820 821 // Create text node for the link text 822 let newText = document.createTextNode(' View R History'); 823 824 // Append <kbd> and text node to <a> 825 newLink.appendChild(newKbd); 826 newLink.appendChild(newText); 827 828 // Append <a> to <li> 829 newListItem.appendChild(newLink); 830 831 // Append <li> to <ul> 832 ulElement.appendChild(newListItem); 833 } 834 835 // Handle setting up the R history modal 836 function qwebrCodeLinks() { 837 838 if (qwebrIsRevealJS()) { 839 qwebrRegisterRevealJSCommandHistoryModal(); 840 return; 841 } 842 843 // Create the container div 844 var containerDiv = document.createElement('div'); 845 containerDiv.className = 'quarto-code-links'; 846 847 // Create the h2 element 848 var h2 = document.createElement('h2'); 849 h2.textContent = 'webR Code Links'; 850 851 // Create the ul element 852 var ul = document.createElement('ul'); 853 854 // Create the li element 855 var li = document.createElement('li'); 856 857 // Create the a_history_btn element 858 var a_history_btn = document.createElement('a'); 859 a_history_btn.href = 'javascript:void(0)'; 860 a_history_btn.setAttribute('id', 'qwebrRHistoryButton'); 861 862 // Create the i_history_btn element 863 var i_history_btn = document.createElement('i'); 864 i_history_btn.className = 'bi bi-file-code'; 865 866 // Create the text node for the link text 867 var text_history_btn = document.createTextNode('View R History'); 868 869 // Append the icon element and link text to the a element 870 a_history_btn.appendChild(i_history_btn); 871 a_history_btn.appendChild(text_history_btn); 872 873 // Append the a element to the li element 874 li.appendChild(a_history_btn); 875 876 // Append the li element to the ul element 877 ul.appendChild(li); 878 879 // Append the h2 and ul elements to the container div 880 containerDiv.appendChild(h2); 881 containerDiv.appendChild(ul); 882 883 // Append the container div to the element with the ID 'quarto-margin-sidebar' 884 var sidebar = document.getElementById('quarto-margin-sidebar'); 885 886 // If the sidebar element is not found, create it 887 if(!sidebar) { 888 qwebrPlaceQuartoSidebar(); 889 } 890 891 // Re-select the sidebar element (if it was just created) 892 sidebar = document.getElementById('quarto-margin-sidebar'); 893 894 895 // If the sidebar element exists, append the container div to it 896 if(sidebar) { 897 // Append the container div to the sidebar 898 sidebar.appendChild(containerDiv); 899 // Force the sidebar to be clickable by removing the 'zindex-bottom' class 900 // added in pre-release: https://github.com/quarto-dev/quarto-cli
900/commit/f0c53a1ffcaa1de4eccbf07803b096898248adcc 901 sidebar.className = 'sidebar margin-sidebar'; 902 } else { 903 // Get a debugger ... 904 console.warn('Element with ID "quarto-margin-sidebar" not found.'); 905 } 906 } 907 908 // Call the function to append the code links for qwebR into the right sidebar 909 qwebrCodeLinks(); 910 911 // Add the command history modal 912 qwebrAddCommandHistoryModal(); 913 914 displayStartupMessage(qwebrShowStartupMessage, qwebrShowHeaderMessage); 915 qwebrOffScreenCanvasSupportWarningMessage(); 916 </script>
916 917
917<script type="module"> 918 // Define a global storage and retrieval solution ---- 919 920 // Store commands executed in R 921 globalThis.qwebrRCommandHistory = []; 922 923 // Function to retrieve the command history 924 globalThis.qwebrFormatRHistory = function() { 925 return qwebrRCommandHistory.join("\n\n"); 926 } 927 928 // Retrieve HTML Elements ---- 929 930 // Get the command modal 931 const command_history_modal = document.getElementById("qwebr-history-modal"); 932 933 // Get the button that opens the command modal 934 const command_history_btn = document.getElementById("qwebrRHistoryButton"); 935 936 // Get the <span> element that closes the command modal 937 const command_history_close_span = document.getElementById("qwebr-command-history-close-btn"); 938 939 // Get the download button for r history information 940 const command_history_download_btn = document.getElementById("qwebr-download-history-btn"); 941 942 // Plug in command history into modal/download button ---- 943 944 // Function to populate the modal with command history 945 function populateCommandHistoryModal() { 946 document.getElementById("qwebr-command-history-contents").innerHTML = qwebrFormatRHistory() || "No commands have been executed yet."; 947 } 948 949 // Function to format the current date and time to 950 // a string with the format YYYY-MM-DD-HH-MM-SS 951 function formatDateTime() { 952 const now = new Date(); 953 954 const year = now.getFullYear(); 955 const day = String(now.getDate()).padStart(2, '0');
956 const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based 957 const hours = String(now.getHours()).padStart(2, '0'); 958 const minutes = String(now.getMinutes()).padStart(2, '0'); 959 const seconds = String(now.getSeconds()).padStart(2, '0'); 960 961 return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}`; 962 } 963 964 965 // Function to convert document title with datetime to a safe filename 966 function safeFileName() { 967 // Get the current page title 968 let pageTitle = document.title; 969 970 // Combine the current page title with the current date and time 971 let pageNameWithDateTime = `Rhistory-${pageTitle}-${formatDateTime()}`; 972 973 // Replace unsafe characters with safe alternatives 974 let safeFilename = pageNameWithDateTime.replace(/[\\/:\*\?! "<>\|]/g, '-'); 975 976 return safeFilename; 977 } 978 979 980 // Function to download list contents as text file 981 function downloadRHistory() { 982 // Get the current page title + datetime and use it as the filename 983 const filename = `${safeFileName()}.R`; 984 985 // Get the text contents of the R History list 986 const text = qwebrFormatRHistory(); 987 988 // Create a new Blob object with the text contents 989 const blob = new Blob([text], { type: 'text/plain' }); 990 991 // Create a new anchor element for the download 992 const a = document.createElement('a'); 993 a.style.display = 'none'; 994 a.href = URL.createObjectURL(blob); 995 a.download = filename; 996 997 // Append the anchor to the body, click it, and remove it 998 document.body.appendChild(a); 999 a.click(); 1000 document.body.removeChild(a); 1001 } 1002 1003 // Register event handlers ---- 1004 1005 // When the user clicks the View R History button, open the command modal 1006 command_history_btn.onclick = function() { 1007 populateCommandHistoryModal(); 1008 command_history_modal.style.display = "block"; 1009 } 1010 1011 // When the user clicks on <span> (x), close the command modal 1012 command_history_close_span.onclick = function() { 1013 command_history_modal.style.display = "none"; 1014 } 1015 1016 // When the user clicks anywhere outside of the command modal, close it 1017 window.onclick = function(event) { 1018 if (event.target == command_history_modal) { 1019 command_history_modal.style.display = "none"; 1020 } 1021 } 1022 1023 // Add an onclick event listener to the download button so that 1024 // the user can download the R history as a text file 1025 command_history_download_btn.onclick = function() { 1026 downloadRHistory(); 1027 }; 1028 </script>
1028 1029
1029<script type="module"> 1030 // Supported Evaluation Types for Context 1031 globalThis.EvalTypes = Object.freeze({ 1032 Interactive: 'interactive', 1033 Setup: 'setup', 1034 Output: 'output', 1035 }); 1036 1037 // Function that obtains the font size for a given element 1038 globalThis.qwebrCurrentFontSizeOnElement = function(element, cssProperty = 'font-size') { 1039 1040 const currentFontSize = parseFloat( 1041 window 1042 .getComputedStyle(element) 1043 .getPropertyValue(cssProperty) 1044 ); 1045 1046 return currentFontSize; 1047 } 1048 1049 // Function to determine font scaling 1050 globalThis.qwebrScaledFontSize = function(div, qwebrOptions) { 1051 // Determine if we should compute font-size using RevealJS's `--r-main-font-size` 1052 // or if we can directly use the document's `font-size`. 1053 const cssProperty = document.body.classList.contains('reveal') ? 1054 "--r-main-font-size" : "font-size"; 1055 1056 // Get the current font size on the div element 1057 const elementFontSize = qwebrCurrentFontSizeOnElement(div, cssProperty); 1058 1059 // Determine the scaled font size value 1060 const scaledFontSize = ((qwebrOptions['editor-font-scale'] ?? 1) * elementFontSize) ?? 17.5; 1061 1062 return scaledFontSize; 1063 } 1064 1065 1066 // Function that dispatches the creation request 1067 globalThis.qwebrCreateHTMLElement = function ( 1068 cellData 1069 ) { 1070 1071 // Extract key components 1072 const evalType = cellData.options.context; 1073 const qwebrCounter = cellData.id; 1074 1075 // We make an assumption that insertion points are defined by the Lua filter as: 1076 // qwebr-insertion-location-{qwebrCounter} 1077 const elementLocator = document.getElementById(`qwebr-insertion-location-${qwebrCounter}`); 1078 1079 // Figure out the routine to use to insert the element. 1080 let qwebrElement; 1081 switch ( evalType ) { 1082 case EvalTypes.Interactive: 1083 qwebrElement = qwebrCreateInteractiveElement(qwebrCounter, cellData.options); 1084 break; 1085 case EvalTypes.Output: 1086 qwebrElement = qwebrCreateNonInteractiveOutputElement(qwebrCounter, cellData.options); 1087 break; 1088 case EvalTypes.Setup: 1089 qwebrElement = qwebrCreateNonInteractiveSetupElement(qwebrCounter, cellData.options); 1090 break; 1091 default: 1092 qwebrElement = document.createElement('div'); 1093 qwebrElement.textContent = 'Error creating `quarto-webr` element'; 1094 } 1095 1096 // Insert the dynamically generated object at the document location. 1097 elementLocator.appendChild(qwebrElement); 1098 }; 1099 1100 // Function that setups the interactive element creation 1101 globalThis.qwebrCreateInteractiveElement = function (qwebrCounter, qwebrOptions) { 1102 1103 // Create main div element 1104 var mainDiv = document.createElement('div'); 1105 mainDiv.id = 'qwebr-interactive-area-' + qwebrCounter; 1106 mainDiv.className = `qwebr-interactive-area`; 1107 if (qwebrOptions.classes) { 1108 mainDiv.className += " " + qwebrOptions.classes 1109 } 1110 1111 // Add a unique cell identifier that users can customize 1112 if (qwebrOptions.label) { 1113 mainDiv.setAttribute('data-id', qwebrOptions.label); 1114 } 1115 1116 // Create toolbar div 1117 var toolbarDiv = document.createElement('div'); 1118 toolbarDiv.className = 'qwebr-editor-toolbar'; 1119 toolbarDiv.id = 'qwebr-editor-toolbar-' + qwebrCounter; 1120 1121 // Create a div to hold the left buttons 1122 var leftButtonsDiv = document.createElement('div'); 1123 leftButtonsDiv.className = 'qwebr-editor-toolbar-left-buttons'; 1124 1125 // Create a div to hold the right buttons 1126 var rightButtonsDiv = document.createElement('div'); 1127 rightButtonsDiv.className = 'qwebr-editor-toolbar-right-buttons'; 1128 1129 // Create Run Code button 1130 var runCodeButton = document.createElement('button'); 1131 runCodeButton.className = 'btn btn-default qwebr-button qwebr-button-run'; 1132 runCodeButton.disabled = true; 1133 runCodeButton.type = 'button'; 1134 runCodeButton.id = 'qwebr-button-run-' + qwebrCounter; 1135 runCodeButton.textContent = 'ð¡ Loading webR...'; 1136 runCodeButton.title = `Run code (Shift + Enter)`; 1137 1138 // Append buttons to the leftButtonsDiv 1139 leftButtonsDiv.appendChild(runCodeButton); 1140 1141 // Create Reset button 1142 var resetButton = document.createElement('button'); 1143 resetButton.className = 'btn btn-light btn-xs qwebr-button qwebr-button-reset'; 1144 resetButton.type = 'button'; 1145 resetButton.id = 'qwebr-button-reset-' + qwebrCounter; 1146 resetButton.title = 'Start over'; 1147 resetButton.innerHTML = '<i class="fa-solid fa-arrows-rotate"></i>'; 1148 1149 // Create Copy button 1150 var copyButton = document.createElement('button'); 1151 copyButton.className = 'btn btn-light btn-xs qwebr-button qwebr-button-copy';
1152 copyButton.type = 'button'; 1153 copyButton.id = 'qwebr-button-copy-' + qwebrCounter; 1154 copyButton.title = 'Copy code'; 1155 copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>'; 1156 1157 // Append buttons to the rightButtonsDiv 1158 rightButtonsDiv.appendChild(resetButton); 1159 rightButtonsDiv.appendChild(copyButton); 1160 1161 // Create console area div 1162 var consoleAreaDiv = document.createElement('div'); 1163 consoleAreaDiv.id = 'qwebr-console-area-' + qwebrCounter; 1164 consoleAreaDiv.className = 'qwebr-console-area'; 1165 1166 // Create editor div 1167 var editorDiv = document.createElement('div'); 1168 editorDiv.id = 'qwebr-editor-' + qwebrCounter; 1169 editorDiv.className = 'qwebr-editor'; 1170 1171 // Create output code area div 1172 var outputCodeAreaDiv = document.createElement('div'); 1173 outputCodeAreaDiv.id = 'qwebr-output-code-area-' + qwebrCounter; 1174 outputCodeAreaDiv.className = 'qwebr-output-code-area'; 1175 outputCodeAreaDiv.setAttribute('aria-live', 'assertive'); 1176 1177 // Create pre element inside output code area 1178 var preElement = document.createElement('pre'); 1179 preElement.style.visibility = 'hidden'; 1180 outputCodeAreaDiv.appendChild(preElement); 1181 1182 // Create output graph area div 1183 var outputGraphAreaDiv = document.createElement('div'); 1184 outputGraphAreaDiv.id = 'qwebr-output-graph-area-' + qwebrCounter; 1185 outputGraphAreaDiv.className = 'qwebr-output-graph-area'; 1186 1187 // Append buttons to the toolbar 1188 toolbarDiv.appendChild(leftButtonsDiv); 1189 toolbarDiv.appendChild(rightButtonsDiv); 1190 1191 // Append all elements to the main div 1192 mainDiv.appendChild(toolbarDiv); 1193 consoleAreaDiv.appendChild(editorDiv); 1194 consoleAreaDiv.appendChild(outputCodeAreaDiv); 1195 mainDiv.appendChild(consoleAreaDiv); 1196 mainDiv.appendChild(outputGraphAreaDiv); 1197 1198 return mainDiv; 1199 } 1200 1201 // Function that adds output structure for non-interactive output 1202 globalThis.qwebrCreateNonInteractiveOutputElement = function(qwebrCounter, qwebrOptions) { 1203 // Create main div element 1204 var mainDiv = document.createElement('div'); 1205 mainDiv.id = 'qwebr-noninteractive-area-' + qwebrCounter; 1206 mainDiv.className = `qwebr-noninteractive-area`; 1207 if (qwebrOptions.classes) { 1208 mainDiv.className += " " + qwebrOptions.classes 1209 } 1210 1211 // Add a unique cell identifier that users can customize 1212 if (qwebrOptions.label) { 1213 mainDiv.setAttribute('data-id', qwebrOptions.label); 1214 } 1215 1216 // Create a status container div 1217 var statusContainer = createLoadingContainer(qwebrCounter); 1218 1219 // Create output code area div 1220 var outputCodeAreaDiv = document.createElement('div'); 1221 outputCodeAreaDiv.id = 'qwebr-output-code-area-' + qwebrCounter; 1222 outputCodeAreaDiv.className = 'qwebr-output-code-area'; 1223 outputCodeAreaDiv.setAttribute('aria-live', 'assertive'); 1224 1225 // Create pre element inside output code area 1226 var preElement = document.createElement('pre'); 1227 preElement.style.visibility = 'hidden'; 1228 outputCodeAreaDiv.appendChild(preElement); 1229 1230 // Create output graph area div 1231 var outputGraphAreaDiv = document.createElement('div'); 1232 outputGraphAreaDiv.id = 'qwebr-output-graph-area-' + qwebrCounter; 1233 outputGraphAreaDiv.className = 'qwebr-output-graph-area'; 1234 1235 // Append all elements to the main div 1236 mainDiv.appendChild(statusContainer); 1237 mainDiv.appendChild(outputCodeAreaDiv); 1238 mainDiv.appendChild(outputGraphAreaDiv); 1239 1240 return mainDiv; 1241 }; 1242 1243 // Function that adds a stub in the page to indicate a setup cell was used. 1244 globalThis.qwebrCreateNonInteractiveSetupElement = function(qwebrCounter, qwebrOptions) { 1245 // Create main div element 1246 var mainDiv = document.createElement('div'); 1247 mainDiv.id = `qwebr-noninteractive-setup-area-${qwebrCounter}`; 1248 mainDiv.className = `qwebr-noninteractive-setup-area`; 1249 if (qwebrOptions.classes) { 1250 mainDiv.className += " " + qwebrOptions.classes 1251 } 1252 1253 1254 // Add a unique cell identifier that users can customize 1255 if (qwebrOptions.label) { 1256 mainDiv.setAttribute('data-id', qwebrOptions.label); 1257 } 1258 1259 // Create a status container div 1260 var statusContainer = createLoadingContainer(qwebrCounter); 1261 1262 // Append status onto the main div 1263 mainDiv.appendChild(statusContainer); 1264 1265 return mainDiv; 1266 } 1267 1268 1269 // Function to create loading container with specified ID 1270 globalThis.createLoadingContainer = function(qwebrCounter) { 1271 1272 // Create a status container 1273 const container = document.createElement('div'); 1274 container.id = `qwebr-non-interactive-loading-container-${qwebrCounter}`; 1275 container.className = 'qwebr-non-interactive-loading-container qwebr-cell-needs-evaluation'; 1276 1277 // Create an R project logo to indicate its a code space 1278 const rProjectIcon = document.createElement('i'); 1279 rProjectIcon.className = 'fa-brands fa-r-project fa-3x qwebr-r-project-logo'; 1280 1281 // Setup a loading icon from font awesome 1282 const spinnerIcon = document.createElement('i'); 1283 spinnerIcon.className = 'fa-solid fa-spinner fa-spin fa-1x qwebr-icon-status-spinner'; 1284 1285 // Add a section for status text 1286 const statusText = document.createElement('p'); 1287 statusText.id = `qwebr-status-text-${qwebrCounter}`; 1288 statusText.className = `qwebr-status-text qwebr-cell-needs-evaluation`; 1289 statusText.innerText = 'Loading webR...'; 1290 1291 // Incorporate an inner container 1292 const innerContainer = document.createElement('div'); 1293 1294 // Append elements to the inner container 1295 innerContainer.appendChild(spinnerIcon); 1296 innerContainer.appendChild(statusText); 1297 1298 // Append elements to the main container 1299 container.appendChild(rProjectIcon); 1300 container.appendChild(innerContainer); 1301 1302 return container; 1303 } 1304 </script>
1304 1305
1305<script type="module"> 1306 // Function to install a single package 1307 async function qwebrInstallRPackage(packageName) { 1308 await mainWebR.evalRVoid(`webr::install('${packageName}');`); 1309 } 1310 1311 // Function to load a single package 1312 async function qwebrLoadRPackage(packageName) { 1313 await mainWebR.evalRVoid(`require('${packageName}', quietly = TRUE)`); 1314 } 1315 1316 // Generic function to process R packages 1317 async function qwebrProcessRPackagesWithStatus(packages, processType, displayStatusMessageUpdate = true) { 1318 // Switch between contexts 1319 const messagePrefix = processType === 'install' ? 'Installing' : 'Loading'; 1320 1321 // Modify button state 1322 qwebrSetInteractiveButtonState(`ð¡ ${messagePrefix} package ...`, false); 1323 1324 // Iterate over packages 1325 for (let i = 0; i < packages.length; i++) { 1326 const activePackage = packages[i]; 1327 const formattedMessage = `${messagePrefix} package ${i + 1} out of ${packages.length}: ${activePackage}`; 1328 1329 // Display the update in header 1330 if (displayStatusMessageUpdate) { 1331 qwebrUpdateStatusHeader(formattedMessage); 1332 } 1333 1334 // Display the update in non-active areas 1335 qwebrUpdateStatusMessage(formattedMessage); 1336 1337 // Run package installation 1338 if (processType === 'install') { 1339 await qwebrInstallRPackage(activePackage); 1340 } else { 1341 await qwebrLoadRPackage(activePackage); 1342 } 1343 } 1344 1345 // Clean slate 1346 if (processType === 'load') { 1347 await mainWebR.flush(); 1348 } 1349 } 1350 1351 // Start a timer 1352 const initializeWebRTimerStart = performance.now(); 1353 1354 // Encase with a dynamic import statement 1355 globalThis.qwebrInstance = import(qwebrCustomizedWebROptions.baseURL + "webr.mjs").then( 1356 async ({ WebR, ChannelType }) => { 1357 // Populate WebR options with defaults or new values based on `webr` meta 1358 globalThis.mainWebR = new WebR(qwebrCustomizedWebROptions); 1359 1360 // Initialization WebR 1361 await mainWebR.init(); 1362 1363 // Setup a shelter 1364 globalThis.mainWebRCodeShelter = await new mainWebR.Shelter(); 1365 1366 // Setup a pager to allow processing help documentation 1367 await mainWebR.evalRVoid('webr::pager_install()'); 1368 1369 // Setup a viewer to allow processing htmlwidgets. 1370 // This might not be available in old webr version 1371 await mainWebR.evalRVoid('try({ webr::viewer_install() })'); 1372 1373 // Override the existing install.packages() to use webr::install() 1374 await mainWebR.evalRVoid('webr::shim_install()'); 1375 1376 // Specify the repositories to pull from 1377 // Note: webR does not use the `repos` option, but instead uses `webr_pkg_repos` 1378 // inside of `install()`. However, other R functions still pull from `repos`. 1379 await mainWebR.evalRVoid(` 1380 options( 1381 webr_pkg_repos = c(${qwebrPackageRepoURLS.map(repoURL => `'${repoURL}'`).join(',')}), 1382 repos = c(${qwebrPackageRepoURLS.map(repoURL => `'${repoURL}'`).join(',')}) 1383 ) 1384 `); 1385 1386 // Check to see if any packages need to be installed 1387 if (qwebrSetupRPackages) { 1388 // Obtain only a unique list of packages 1389 const uniqueRPackageList = Array.from(new Set(qwebrInstallRPackagesList)); 1390 1391 // Install R packages one at a time (either silently or with a status update) 1392 await qwebrProcessRPackagesWithStatus(uniqueRPackageList, 'install', qwebrShowStartupMessage); 1393 1394 if (qwebrAutoloadRPackages) { 1395 // Load R packages one at a time (either silently or with a status update) 1396 await qwebrProcessRPackagesWithStatus(uniqueRPackageList, 'load', qwebrShowStartupMessage); 1397 } 1398 } 1399 } 1400 ); 1401 1402 // Stop timer 1403 const initializeWebRTimerEnd = performance.now(); 1404 1405 </script>
1405 1406
1406<script type="module"> 1407 // Function to verify a given JavaScript Object is empty 1408 globalThis.qwebrIsObjectEmpty = function (arr) { 1409 return Object.keys(arr).length === 0; 1410 } 1411 1412 // Global version of the Escape HTML function that converts HTML 1413 // characters to their HTML entities. 1414 globalThis.qwebrEscapeHTMLCharacters = function(unsafe) { 1415 return unsafe 1416 .replace(/&/g, "&") 1417 .replace(/</g, "<") 1418 .replace(/>/g, ">") 1419 .replace(/"/g, """) 1420 .replace(/'/g, "'"); 1421 }; 1422 1423 // Passthrough results 1424 globalThis.qwebrIdentity = function(x) { 1425 return x; 1426 }; 1427 1428 // Append a comment 1429 globalThis.qwebrPrefixComment = function(x, comment) { 1430 return `${comment}${x}`; 1431 }; 1432 1433 // Function to store the code in the history 1434 globalThis.qwebrLogCodeToHistory = function(codeToRun, options) { 1435 qwebrRCommandHistory.push( 1436 `# Ran code in ${options.label} at ${new Date().toLocaleString()} ----\n${codeToRun}` 1437 ); 1438 }; 1439 1440 // Function to attach a download button onto the canvas 1441 // allowing the user to download the image. 1442 function qwebrImageCanvasDownloadButton(canvas, canvasContainer) { 1443 1444 // Create the download button 1445 const downloadButton = document.createElement('button'); 1446 downloadButton.className = 'qwebr-canvas-image-download-btn'; 1447 downloadButton.textContent = 'Download Image'; 1448 canvasContainer.appendChild(downloadButton); 1449 1450 // Trigger a download of the image when the button is clicked 1451 downloadButton.addEventListener('click', function() { 1452 const image = canvas.toDataURL('image/png'); 1453 const link = document.createElement('a'); 1454 link.href = image; 1455 link.download = 'qwebr-canvas-image.png'; 1456 link.click(); 1457 }); 1458 } 1459 1460 1461 // Function to parse the pager results 1462 globalThis.qwebrParseTypePager = async function (msg) { 1463 1464 // Split out the event data 1465 const { path, title, deleteFile } = msg.data; 1466 1467 // Process the pager data by reading the information from disk 1468 const paged_data = await mainWebR.FS.readFile(path).then((data) => { 1469 // Obtain the file content 1470 let content = new TextDecoder().decode(data); 1471 1472 // Remove excessive backspace characters until none remain 1473 while(content.match(/.[\b]/)){ 1474 content = content.replace(/.[\b]/g, ''); 1475 } 1476 1477 // Returned cleaned data 1478 return content; 1479 }); 1480 1481 // Unlink file if needed 1482 if (deleteFile) { 1483 await mainWebR.FS.unlink(path); 1484 } 1485 1486 // Return extracted data with spaces 1487 return paged_data; 1488 }; 1489 1490 1491 // Function to parse the browse results 1492 globalThis.qwebrParseTypeBrowse = async function (msg) { 1493 1494 // msg.type === "browse" 1495 const path = msg.data.url; 1496 1497 // Process the browse data by reading the information from disk 1498 const browse_data = await mainWebR.FS.readFile(path).then((data) => { 1499 // Obtain the file content 1500 let content = new TextDecoder().decode(data); 1501 1502 return content; 1503 }); 1504 1505 // Return extracted data as-is 1506 return browse_data; 1507 }; 1508 1509 // Function to run the code using webR and parse the output 1510 globalThis.qwebrComputeEngine = async function( 1511 codeToRun, 1512 elements, 1513 options) { 1514 1515 // Call into the R compute engine that persists within the document scope. 1516 // To be prepared for all scenarios, the following happens: 1517 // 1. We setup a canvas device to write to by making a namespace call into the {webr} package 1518 // 2. We use values inside of the options array to set the figure size. 1519 // 3. We capture the output stream information (STDOUT and STERR) 1520 // 4. We disable the current device's image creation. 1521 // 5. Piece-wise parse the results into the different output areas 1522 1523 // Create a pager variable for help/file contents 1524 let pager = []; 1525 1526 // Handle how output is processed 1527 let showMarkup = options.results === "markup" && options.output !== "asis"; 1528 let processOutput; 1529 1530 if (showMarkup) { 1531 processOutput = qwebrEscapeHTMLCharacters; 1532 } else { 1533 processOutput = qwebrIdentity; 1534 } 1535 1536 // ---- 1537 // Convert from Inches to Pixels by using DPI (dots per inch) 1538 // for bitmap devices (dpi * inches = pixels) 1539 let fig_width = options["fig-width"] * options["dpi"]; 1540 let fig_height = options["fig-height"] * options["dpi"]; 1541 1542 // Initialize webR 1543 await mainWebR.init(); 1544 1545 // Configure capture output 1546 let captureOutputOptions = { 1547 withAutoprint: true, 1548 captureStreams: true, 1549 captureConditions: false, 1550 // env: webR.objs.emptyEnv, // maintain a global environment for webR v0.2.0 1551 }; 1552 1553 // Determine if the browser supports OffScreen 1554 if (qwebrOffScreenCanvasSupport()) { 1555 // Mirror default options of webr::canvas() 1556 // with changes to figure height and width. 1557 captureOutputOptions.captureGraphics = { 1558 width: fig_width, 1559 height: fig_height, 1560 bg: "white", // default: transparent 1561 pointsize: 12, 1562 capture: true 1563 }; 1564 } else { 1565 // Disable generating graphics 1566 captureOutputOptions.captureGraphics = false;
1567 } 1568 1569 // Store the code to run in history 1570 qwebrLogCodeToHistory(codeToRun, options); 1571 1572 // Setup a webR canvas by making a namespace call into the {webr} package 1573 // Evaluate the R code 1574 // Remove the active canvas silently 1575 const result = await mainWebRCodeShelter.captureR( 1576 `${codeToRun}`, 1577 captureOutputOptions 1578 ); 1579 1580 // ----- 1581 1582 // Start attempting to parse the result data 1583 processResultOutput:try { 1584 1585 // Avoid running through output processing 1586 if (options.results === "hide" || options.output === "false") { 1587 break processResultOutput; 1588 } 1589 1590 // Merge output streams of STDOUT and STDErr (messages and errors are combined.) 1591 // Require both `warning` and `message` to be true to display `STDErr`. 1592 const out = result.output 1593 .filter( 1594 evt => evt.type === "stdout" || 1595 ( evt.type === "stderr" && (options.warning === "true" && options.message === "true")) 1596 ) 1597 .map((evt, index) => { 1598 const className = `qwebr-output-code-${evt.type}`; 1599 const outputResult = qwebrPrefixComment(processOutput(evt.data), options.comment); 1600 return `<code id="${className}-editor-${elements.id}-result-${index + 1}" class="${className}">${outputResult}</code>`; 1601 }) 1602 .join("\n"); 1603 1604 1605 // Clean the state 1606 // We're now able to process pager events. 1607 // As a result, we cannot maintain a true 1-to-1 output order 1608 // without individually feeding each line 1609 const msgs = await mainWebR.flush(); 1610 1611 // Use `map` to process the filtered "pager" events asynchronously 1612 const pager = []; 1613 const browse = []; 1614 1615 await Promise.all( 1616 msgs.map( 1617 async (msg) => { 1618 1619 const msgType = msg.type || "unknown"; 1620 1621 switch(msgType) { 1622 case 'pager': 1623 const pager_data = await qwebrParseTypePager(msg); 1624 pager.push(pager_data); 1625 break; 1626 case 'browse': 1627 const browse_data = await qwebrParseTypeBrowse(msg); 1628 browse.push(browse_data); 1629 break; 1630 } 1631 return; 1632 } 1633 ) 1634 ); 1635 1636 // Nullify the output area of content 1637 elements.outputCodeDiv.innerHTML = ""; 1638 elements.outputGraphDiv.innerHTML = ""; 1639 1640 // Design an output object for messages 1641 const pre = document.createElement("pre"); 1642 if (/\S/.test(out)) { 1643 // Display results as HTML elements to retain output styling 1644 const div = document.createElement("div"); 1645 div.innerHTML = out; 1646 1647 // Calculate a scaled font-size value 1648 const scaledFontSize = qwebrScaledFontSize( 1649 elements.outputCodeDiv, options); 1650 1651 // Override output code cell size 1652 pre.style.fontSize = `${scaledFontSize}px`; 1653 pre.appendChild(div); 1654 } else { 1655 // If nothing is present, hide the element. 1656 pre.style.visibility = "hidden"; 1657 } 1658 1659 elements.outputCodeDiv.appendChild(pre); 1660 1661 // Determine if we have graphs to display 1662 if (result.images.length > 0) { 1663 1664 // Create figure element 1665 const figureElement = document.createElement("figure"); 1666 figureElement.className = "qwebr-canvas-image"; 1667 1668 // Place each rendered graphic onto a canvas element 1669 result.images.forEach((img) => { 1670 1671 // Construct canvas for object 1672 const canvas = document.createElement("canvas"); 1673 1674 // Add an image download button 1675 qwebrImageCanvasDownloadButton(canvas, figureElement); 1676 1677 // Set canvas size to image 1678 canvas.width = img.width;
1679 canvas.height = img.height; 1680 1681 // Apply output truncations 1682 canvas.style.width = options["out-width"] ? options["out-width"] : `${fig_width}px`; 1683 if (options["out-height"]) { 1684 canvas.style.height = options["out-height"]; 1685 } 1686 1687 // Apply styling 1688 canvas.style.display = "block"; 1689 canvas.style.margin = "auto"; 1690 1691 // Draw image onto Canvas 1692 const ctx = canvas.getContext("2d"); 1693 ctx.drawImage(img, 0, 0, img.width, img.height); 1694 1695 // Append canvas to figure output area 1696 figureElement.appendChild(canvas); 1697 1698 }); 1699 1700 if (options['fig-cap']) { 1701 // Create figcaption element 1702 const figcaptionElement = document.createElement('figcaption'); 1703 figcaptionElement.innerText = options['fig-cap']; 1704 // Append figcaption to figure 1705 figureElement.appendChild(figcaptionElement); 1706 } 1707 1708 elements.outputGraphDiv.appendChild(figureElement); 1709 1710 } 1711 1712 // Display the pager data 1713 if (pager.length > 0) { 1714 // Use the `pre` element to preserve whitespace. 1715 pager.forEach((paged_data, index) => { 1716 const pre_pager = document.createElement("pre"); 1717 pre_pager.innerText = paged_data; 1718 pre_pager.classList.add("qwebr-output-code-pager"); 1719 pre_pager.setAttribute("id", `qwebr-output-code-pager-editor-${elements.id}-result-${index + 1}`); 1720 elements.outputCodeDiv.appendChild(pre_pager); 1721 }); 1722 } 1723 1724 // Display the browse data 1725 if (browse.length > 0) { 1726 // Use the `pre` element to preserve whitespace. 1727 browse.forEach((browse_data, index) => { 1728 const iframe_browse = document.createElement('iframe'); 1729 iframe_browse.classList.add("qwebr-output-code-browse"); 1730 iframe_browse.setAttribute("id", `qwebr-output-code-browse-editor-${elements.id}-result-${index + 1}`); 1731 iframe_browse.style.width = "100%"; 1732 iframe_browse.style.minHeight = "500px"; 1733 elements.outputCodeDiv.appendChild(iframe_browse); 1734 1735 iframe_browse.contentWindow.document.open(); 1736 iframe_browse.contentWindow.document.write(browse_data); 1737 iframe_browse.contentWindow.document.close(); 1738 }); 1739 } 1740 } finally { 1741 // Clean up the remaining code 1742 mainWebRCodeShelter.purge(); 1743 } 1744 }; 1745 1746 // Function to execute the code (accepts code as an argument) 1747 globalThis.qwebrExecuteCode = async function ( 1748 codeToRun, 1749 id, 1750 options = {}) { 1751 1752 // If options are not passed, we fall back on the bare minimum to handle the computation 1753 if (qwebrIsObjectEmpty(options)) { 1754 options = { 1755 "context": "interactive", 1756 "fig-width": 7, "fig-height": 5, 1757 "out-width": "700px", "out-height": "", 1758 "dpi": 72, 1759 "results": "markup", 1760 "warning": "true", "message": "true", 1761 }; 1762 } 1763 1764 // Next, we access the compute areas values 1765 const elements = { 1766 runButton: document.getElementById(`qwebr-button-run-${id}`), 1767 outputCodeDiv: document.getElementById(`qwebr-output-code-area-${id}`), 1768 outputGraphDiv: document.getElementById(`qwebr-output-graph-area-${id}`), 1769 id: id, 1770 } 1771 1772 // Disallowing execution of other code cells 1773 document.querySelectorAll(".qwebr-button-run").forEach((btn) => { 1774 btn.disabled = true; 1775 }); 1776 1777 if (options.context == EvalTypes.Interactive) { 1778 // Emphasize the active code cell 1779 elements.runButton.innerHTML = '<i class="fa-solid fa-spinner fa-spin qwebr-icon-status-spinner"></i> <span>
1779Run Code</span>'; 1780 } 1781 1782 // Evaluate the code and parse the output into the document 1783 await qwebrComputeEngine(codeToRun, elements, options); 1784 1785 // Switch to allowing execution of code 1786 document.querySelectorAll(".qwebr-button-run").forEach((btn) => { 1787 btn.disabled = false; 1788 }); 1789 1790 if (options.context == EvalTypes.Interactive) { 1791 // Revert to the initial code cell state 1792 elements.runButton.innerHTML = '<i class="fa-solid fa-play qwebr-icon-run-code"></i> <span>Run Code</span>'; 1793 } 1794 } 1795 1796 </script>
1796 1797</head> 1798<body class="quarto-light">
1799<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/loader.js"></script>
vendor: 1 bytes, line 1799
1799
1800<script type="module" id="qwebr-monaco-editor-init"> 1801 1802 // Configure the Monaco Editor's loader 1803 require.config({ 1804 paths: { 1805 'vs': 'https://cdn.jsdelivr.net/npm/[email protected]/min/vs' 1806 } 1807 }); 1808</script>
vendor: 1 bytes, line 1808
1808
1809<script type="module"> 1810// Function to update Monaco Editors when body class changes 1811function updateMonacoEditorsOnBodyClassChange() { 1812 // Select the body element 1813 const body = document.querySelector('body'); 1814 1815 // Options for the observer (which mutations to observe) 1816 const observerOptions = { 1817 attributes: true, // Observe changes to attributes 1818 attributeFilter: ['class'] // Only observe changes to the 'class' attribute 1819 }; 1820 1821 // Callback function to execute when mutations are observed 1822 const bodyClassChangeCallback = function(mutationsList, observer) { 1823 for(let mutation of mutationsList) { 1824 if (mutation.type === 'attributes' && mutation.attributeName === 'class') { 1825 // Class attribute has changed 1826 // Update all Monaco Editors on the page 1827 updateMonacoEditorTheme(); 1828 } 1829 } 1830 }; 1831 1832 // Create an observer instance linked to the callback function 1833 const observer = new MutationObserver(bodyClassChangeCallback); 1834 1835 // Start observing the target node for configured mutations 1836 observer.observe(body, observerOptions); 1837} 1838 1839// Function to update all instances of Monaco Editors on the page 1840function updateMonacoEditorTheme() { 1841 // Determine what VS Theme to use 1842 const vsThemeToUse = document.body.classList.contains("quarto-dark") ? 'vs-dark' : 'vs' ; 1843 1844 // Iterate through all initialized Monaco Editors 1845 qwebrEditorInstances.forEach( function(editorInstance) { 1846 editorInstance.updateOptions({ theme: vsThemeToUse }); 1847 }); 1848} 1849 1850// Call the function to start observing changes to body class 1851updateMonacoEditorsOnBodyClassChange(); 1852</script>
vendor: 1 bytes, line 1852
1852
1853<script type="module"> 1854// Global array to store Monaco Editor instances 1855globalThis.qwebrEditorInstances = []; 1856 1857function isValidCodeLineNumbers(stringCodeLineNumbers) { 1858 // Regular expression to match valid input strings 1859 const regex = /^(\d+(-\d+)?)(,\d+(-\d+)?)*$/; 1860 return regex.test(stringCodeLineNumbers); 1861} 1862 1863// Function that builds and registers a Monaco Editor instance 1864globalThis.qwebrCreateMonacoEditorInstance = function (cellData) { 1865 1866 const initialCode = cellData.code; 1867 const qwebrCounter = cellData.id; 1868 const qwebrOptions = cellData.options; 1869 1870 // Retrieve the previously created document elements 1871 let runButton = document.getElementById(`qwebr-button-run-${qwebrCounter}`); 1872 let resetButton = document.getElementById(`qwebr-button-reset-${qwebrCounter}`); 1873 let copyButton = document.getElementById(`qwebr-button-copy-${qwebrCounter}`); 1874 let editorDiv = document.getElementById(`qwebr-editor-${qwebrCounter}`); 1875 1876 // Load the Monaco Editor and create an instance 1877 let editor; 1878 require(['vs/editor/editor.main'], function () { 1879 editor = monaco.editor.create(editorDiv, { 1880 value: initialCode, 1881 language: 'r', 1882 theme: 'vs-light', 1883 automaticLayout: true, // Works wonderfully with RevealJS 1884 scrollBeyondLastLine: false, 1885 minimap: { 1886 enabled: false 1887 }, 1888 fontSize: qwebrScaledFontSize(editorDiv, qwebrOptions), 1889 renderLineHighlight: "none", // Disable current line highlighting 1890 hideCursorInOverviewRuler: true, // Remove cursor indictor in right hand side scroll bar 1891 readOnly: qwebrOptions['read-only'] ?? false, 1892 quickSuggestions: qwebrOptions['editor-quick-suggestions'] ?? false, 1893 wordWrap: (qwebrOptions['editor-word-wrap'] == 'true' ? "on" : "off") 1894 }); 1895 1896 // Store the official counter ID to be used in keyboard shortcuts 1897 editor.__qwebrCounter = qwebrCounter; 1898 1899 // Store the official div container ID 1900 editor.__qwebrEditorId = `qwebr-editor-${qwebrCounter}`; 1901 1902 // Store the initial code value and options 1903 editor.__qwebrinitialCode = initialCode; 1904 editor.__qwebrOptions = qwebrOptions; 1905 1906 // Set at the model level the preferred end of line (EOL) character to LF. 1907 // This prevent `\r\n` from being given to the webR engine if the user is on Windows. 1908 // See details in: https://github.com/coatless/quarto-webr/issues/94 1909 // Associated error text: 1910 // Error: <text>:1:7 unexpected input 1911 1912 // Retrieve the underlying model 1913 const model = editor.getModel(); 1914 // Set EOL for the model 1915 model.setEOL(monaco.editor.EndOfLineSequence.LF); 1916 1917 // Dynamically modify the height of the editor window if new lines are added. 1918 let ignoreEvent = false; 1919 const updateHeight = () => { 1920 // Increment editor height by 2 to prevent vertical scroll bar from appearing 1921 const contentHeight = editor.getContentHeight() + 2; 1922 1923 // Retrieve editor-max-height option 1924 const maxEditorHeight = qwebrOptions['editor-max-height']; 1925 1926 // If editor-max-height is missing, allow infinite growth. Otherwise, threshold. 1927 const editorHeight = !maxEditorHeight ? contentHeight : Math.min(contentHeight, maxEditorHeight); 1928 1929 // We're avoiding a width change 1930 //editorDiv.style.width = `${width}px`; 1931 editorDiv.style.height = `${editorHeight}px`; 1932 try { 1933 ignoreEvent = true; 1934 1935 // The key to resizing is this call 1936 editor.layout(); 1937 } finally { 1938 ignoreEvent = false; 1939 } 1940 }; 1941 1942 // Function to generate decorations to highlight lines 1943 // in the editor based on input string. 1944 function decoratorHighlightLines(codeLineNumbers) { 1945 // Store the lines to be lighlight 1946 let linesToHighlight = []; 1947 1948 // Parse the codeLineNumbers string to get the line numbers to highlight 1949 // First, split the string by commas 1950 codeLineNumbers.split(',').forEach(part => { 1951 // Check if we have a range of lines 1952 if (part.includes('-')) { 1953 // Handle range of lines (e.g., "6-8") 1954 const [start, end] = part.split('-').map(Number); 1955 for (let i = start; i <= end; i++) { 1956 linesToHighlight.push(i); 1957 } 1958 } else { 1959 // Handle single line (e.g., "7") 1960 linesToHighlight.push(Number(part)); 1961 } 1962 }); 1963 1964 // Create monaco decorations for the lines to highlight 1965 const decorations = linesToHighlight.map(lineNumber => ({ 1966 range: new monaco.Range(lineNumber, 1, lineNumber, 1), 1967 options: { 1968 isWholeLine: true, 1969 className: 'qwebr-editor-highlight-line' 1970 } 1971 })); 1972 1973 // Return decorations to be applied to the editor
1974 return decorations; 1975 } 1976 1977 // Ensure that the editor-code-line-numbers option is set and valid 1978 // then apply styling 1979 if (qwebrOptions['editor-code-line-numbers']) { 1980 // Remove all whitespace from the string 1981 const codeLineNumbers = qwebrOptions['editor-code-line-numbers'].replace(/\s/g,''); 1982 // Check if the string is valid for line numbers, e.g., "1,3-5,7" 1983 if (isValidCodeLineNumbers(codeLineNumbers)) { 1984 // Apply the decorations to the editor 1985 editor.createDecorationsCollection(decoratorHighlightLines(codeLineNumbers)); 1986 } else { 1987 // Warn the user that the input is invalid 1988 console.warn(`Invalid "editor-code-line-numbers" value in code cell ${qwebrOptions['label']}: ${codeLineNumbers}`); 1989 } 1990 } 1991 1992 // Helper function to check if selected text is empty 1993 function isEmptyCodeText(selectedCodeText) { 1994 return (selectedCodeText === null || selectedCodeText === undefined || selectedCodeText === ""); 1995 } 1996 1997 // Registry of keyboard shortcuts that should be re-added to each editor window 1998 // when focus changes. 1999 const addWebRKeyboardShortCutCommands = () => { 2000 // Add a keydown event listener for Shift+Enter to run all code in cell 2001 editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, () => { 2002 2003 // Retrieve all text inside the editor 2004 qwebrExecuteCode(editor.getValue(), editor.__qwebrCounter, editor.__qwebrOptions); 2005 }); 2006 2007 // Add a keydown event listener for CMD/Ctrl+Enter to run selected code 2008 editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => { 2009 2010 // Get the selected text from the editor 2011 const selectedText = editor.getModel().getValueInRange(editor.getSelection()); 2012 // Check if no code is selected 2013 if (isEmptyCodeText(selectedText)) { 2014 // Obtain the current cursor position 2015 let currentPosition = editor.getPosition(); 2016 // Retrieve the current line content 2017 let currentLine = editor.getModel().getLineContent(currentPosition.lineNumber); 2018 2019 // Propose a new position to move the cursor to 2020 let newPosition = new monaco.Position(currentPosition.lineNumber + 1, 1); 2021 2022 // Check if the new position is beyond the last line of the editor 2023 if (newPosition.lineNumber > editor.getModel().getLineCount()) { 2024 // Add a new line at the end of the editor 2025 editor.executeEdits("addNewLine", [{ 2026 range: new monaco.Range(newPosition.lineNumber, 1, newPosition.lineNumber, 1), 2027 text: "\n", 2028 forceMoveMarkers: true, 2029 }]); 2030 } 2031 2032 // Run the entire line of code. 2033 qwebrExecuteCode(currentLine, editor.__qwebrCounter, editor.__qwebrOptions); 2034 2035 // Move cursor to new position 2036 editor.setPosition(newPosition); 2037 } else { 2038 // Code to run when Ctrl+Enter is pressed with selected code 2039 qwebrExecuteCode(selectedText, editor.__qwebrCounter, editor.__qwebrOptions); 2040 } 2041 }); 2042 } 2043 2044 // Register an on focus event handler for when a code cell is selected to update 2045 // what keyboard shortcut commands should work. 2046 // This is a workaround to fix a regression that happened with multiple 2047 // editor windows since Monaco 0.32.0 2048 // https://github.com/microsoft/monaco-editor/issues/2947 2049 editor.onDidFocusEditorText(addWebRKeyboardShortCutCommands); 2050 2051 // Register an on change event for when new code is added to the editor window 2052 editor.onDidContentSizeChange(updateHeight); 2053 2054 // Manually re-update height to account for the content we inserted into the call 2055 updateHeight(); 2056 2057 // Store the editor instance in the global dictionary 2058 qwebrEditorInstances[editor.__qwebrCounter] = editor; 2059 2060 }); 2061 2062 // Add a click event listener to the run button 2063 runButton.onclick = function () { 2064 qwebrExecuteCode(editor.getValue(), editor.__qwebrCounter, editor.__qwebrOptions); 2065 }; 2066 2067 // Add a click event listener to the reset button 2068 copyButton.onclick = function () { 2069 // Retrieve current code data 2070 const data = editor.getValue(); 2071 2072 // Write code data onto the clipboard. 2073 navigator.clipboard.writeText(data || ""); 2074 }; 2075 2076 // Add a click event listener to the copy button 2077 resetButton.onclick = function () { 2078 editor.setValue(editor.__qwebrinitialCode); 2079 }; 2080 2081} 2082</script>
2082 2083 <div class="reveal"> 2084 <div class="slides"> 2085 2086<section id="title-slide" class="quarto-title-block center"> 2087 <h1 class="title"><p><span style="color:#a9a9a9;">Week 6</span><br> 2088Cleaning and Data<br> 2089Analysis in <svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg></p></h1> 2090 <p class="subtitle"><span style="color:#9c9c9c; font-family: Dynalight; font-size: 130%;">Sociâ269</span></p> 2091 2092<div class="quarto-title-authors"> 2093<div class="quarto-title-author"> 2094<div class="quarto-title-author-name"> 2095Sakeef M. Karim <br><span style="font-size: 80%; color:#9c9c9c;"><em>Amherst College</em></span><br><a href="https://www.sakeefkarim.com" class="external" target="_blank"><svg aria-hidden="true" role="img" viewbox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M352 256c0 22.2-1.2 43.6-3.3 64H163.3c-2.2-20.4-3.3-41.8-3.3-64s1.2-43.6 3.3-64H348.7c2.2 20.4 3.3 41.8 3.3 64zm28.8-64H503.9c5.3 20.5 8.1 41.9 8.1 64s-2.8 43.5-8.1 64H380.8c2.1-20.6 3.2-42 3.2-64s-1.1-43.4-3.2-64zm112.6-32H376.7c-10-63.9-29.8-117.4-55.3-151.6c78.3 20.7 142 77.5 171.9 151.6zm-149.1 0H167.7c6.1-36.4 15.5-68.6 27-94.7c10.5-23.6 22.2-40.7 33.5-51.5C239.4 3.2 248.7 0 256 0s16.6 3.2 27.8 13.8c11.3 10.8 23 27.9 33.5 51.5c11.6 26 20.9 58.2 27 94.7zm-209 0H18.6C48.6 85.9 112.2 29.1 190.6 8.4C165.1 42.6 145.3 96.1 135.3 160zM8.1 192H131.2c-2.1 20.6-3.2 42-3.2 64s1.1 43.4 3.2 64H8.1C2.8 299.5 0 278.1 0 256s2.8-43.5 8.1-64zM194.7 446.6c-11.6-26-20.9-58.2-27-94.6H344.3c-6.1 36.4-15.5 68.6-27 94.6c-10.5 23.6-22.2 40.7-33.5 51.5C272.6 508.8 263.3 512 256 512s-16.6-3.2-27.8-13.8c-11.3-10.8-23-27.9-33.5-51.5zM135.3 352c10 63.9 29.8 117.4 55.3 151.6C112.2 482.9 48.6 426.1 18.6 352H135.3zm358.1 0c-30 74.1-93.6 130.9-171.9 151.6c25.5-34.2 45.2-87.7 55.3-151.6H493.4z"></path></svg></a> <a href="mailto:[email protected]"><svg aria-hidden="true" role="img" viewbox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z"></path></svg></a> <br> <span style="font-weight: 300; font-size: 60%; color: #9c9c9c;">AN INTRODUCTION TO QUANTITATIVE SOCIOLOGYâCULTURE & POWER</span> 2096</div> 2097</div> 2098</div> 2099 2100</section> 2101<section> 2102<section id="data-wrangling-i-october-6th" class="title-slide slide level1 center" data-background-color="#43464B"> 2103<h1>Data Wrangling Iâ<br>October 6<span style="font-size: 70%;"><sup>th</sup></span></h1> 2104 2105</section> 2106<section id="lets-get-things-started" class="slide level2"> 2107<h2>Letâs Get Things Started</h2> 2108<div class="centre-text"> 2109<div class="augmenter"> 2110<p>Make sure youâre ⦠well, here on this slide.</p> 2111</div> 2112</div> 2113</section> 2114<section id="lets-get-things-started-1" class="slide level2"> 2115<h2>Letâs Get Things Started</h2> 2116<div style="text-align: center; margin-top: 30px; margin-bottom: 10px;"> 2117<p>In 1-2 weeks, weâll all be able to produce plots like this.</p> 2118</div> 2119<div class="cell"> 2120<div class="cell-output-display"> 2121<div> 2122<figure> 2123<p><a href="index_files/figure-revealjs/gapminder-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img data-src="index_files/figure-revealjs/gapminder-1.png" width="6000"></a></p> 2124</figure> 2125</div> 2126</div> 2127</div> 2128</section> 2129<section id="lets-get-things-started-2" class="slide level2"> 2130<h2>Letâs Get Things Started</h2> 2131<div class="centre-text"> 2132<p>But letâs take things one step at a time.</p> 2133</div> 2134</section></section> 2135<section> 2136<section id="the-absolute-basics" class="title-slide slide level1 center" data-background-color="#43464B"> 2137<h1>The Absolute Basics</h1> 2138 2139</section> 2140<section id="calculations" class="slide level2"> 2141<h2>Calculations</h2> 2142<div style="text-align: center; margin-top: 80px;"> 2143<p>You can use your <svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> console as a calculator.</p> 2144</div> 2145<div class="fragment"> 2146<div id="qwebr-insertion-location-1"></div> 2147<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2148<div style="text-align: center; font-size: 70%; color: #9c9c9c;"> 2149<p>Feel free to play around with the numbers above.</p> 2150</div> 2151</div> 2152<div class="fragment"> 2153<div style="text-align: center; margin-top:25px;"> 2154<p>Whatâs <code>18%</code> of <code>905</code>? Use the <svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> console on this slide to arrive at an answer.</p> 2155</div> 2156</div> 2157<div class="scrollable-note"> 2158<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2159</div> 2160</section> 2161<section id="combining-elements" class="slide level2"> 2162<h2>Combining Elements</h2> 2163<div style="margin-top: 40px; text-align: center;"> 2164<p>Use the combine functionâ<code>c()</code>âto stitch together multiple elements of the same type, yielding an atomic vector.</p> 2165</div> 2166<div class="fragment"> 2167<div style="text-align: center;"> 2168<p><span style="font-size: 70%; color: #9c9c9c;">Hereâs a character vector.</span></p> 2169</div> 2170<div id="qwebr-insertion-location-2"></div> 2171<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2172</div> 2173<div class="fragment"> 2174<div style="text-align: center;"> 2175<p><span style="font-size: 70%; color: #9c9c9c;">And hereâs a numeric vector.</span></p> 2176</div> 2177<div id="qwebr-insertion-location-3"></div> 2178<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2179</div> 2180<div class="scrollable-note"> 2181<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2182</div> 2183</section> 2184<section id="the-assignment-operator" class="slide level2"> 2185<h2>The Assignment Operator</h2> 2186<div style="text-align: center; margin-top: 80px;"> 2187<p>We can create new objects with the assignment operator <code><-</code>.</p> 2188</div> 2189<div class="fragment"> 2190<div style="text-align: center;"> 2191<p><span style="font-size: 70%; color: #9c9c9c;">
2191Hereâs how we can store the vector <code>c(1, 2, 3)</code> as an object named <code>x</code>.</span></p> 2192</div> 2193<div id="qwebr-insertion-location-4"></div> 2194<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2195</div> 2196<div style="margin-top: 20px;"> 2197 2198</div> 2199<div class="fragment"> 2200<div style="text-align: center;"> 2201<p><span style="font-size: 70%; color: #9c9c9c;">Can you store the character vector embedded below as a new object named <span style="font-size: 90%;"><code>five_colleges</code></span>?</span></p> 2202</div> 2203<div id="qwebr-insertion-location-5"></div> 2204<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2205</div> 2206<div class="scrollable-note"> 2207<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2208</div> 2209</section> 2210<section id="naming-conventions" class="slide level2"> 2211<h2>Naming Conventions</h2> 2212<div style="text-align: center; margin-top: 100px;"> 2213<p>Try to run the line below.</p> 2214</div> 2215<div id="qwebr-insertion-location-6"></div> 2216<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2217<div style="text-align: center; margin-top: 30px; font-size: 85%;"> 2218<details> 2219<summary> 2220A Question 2221</summary> 2222<span style="font-size:90%;">What went awry?</span> 2223</details> 2224</div> 2225<div class="fragment"> 2226<div style="text-align: center; font-size: 90%; color: #838383;"> 2227<p>As Wickham, Ãetinkaya-Rundel and Grolemund <span class="citation" data-cites="wickham_r_2023">(<a href="#/references" role="doc-biblioref" onclick="">2023</a>)</span> note, âobject names <span style="color: white; background-color: #5d3c85; padding: 1px 5px;">must start with a letter</span> and can only contain letters, numbers, <code>_</code>, and <code>.</code>.â</p> 2228</div> 2229</div> 2230<div class="scrollable-note"> 2231<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2232</div> 2233</section> 2234<section id="data-frames-and-base-functions" class="slide level2"> 2235<h2>Data Frames and Base Functions</h2> 2236<div style="text-align: center; margin-top: 50px;"> 2237<p><svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> is particularly useful for working with data frames.</p> 2238</div> 2239<div class="fragment"> 2240<div style="text-align: center;"> 2241<p><span style="font-size: 70%; color: #9c9c9c;">Change the name of this data frame to <code>IRIS</code>.</span></p> 2242</div> 2243<div id="qwebr-insertion-location-7"></div> 2244<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2245</div> 2246<div class="fragment"> 2247<div style="text-align: center; margin-top: 20px; font-size: 90%;"> 2248<p>We can use the <code>$</code> operator to isolate elements within <code>list</code> or <code>data.frame</code> objects. This comes in handy when we use basic functions in <svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg>.</p> 2249</div> 2250</div> 2251<div class="fragment"> 2252<div id="qwebr-insertion-location-8"></div> 2253<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2254<div style="text-align: center;"> 2255<p><span style="font-size: 70%; color: #9c9c9c;">Now, calculate the mean of the <code>Petal.Length</code> variable in <code>iris</code>.</span></p> 2256</div> 2257</div> 2258<div class="scrollable-note"> 2259<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2260</div> 2261</section> 2262<section id="annotations" class="slide level2"> 2263<h2>Annotations</h2> 2264<div style="text-align: center; margin-top: 60px;"> 2265<p>We can annotate our code using the <code>
2265#</code> sign.</p> 2266</div> 2267<div class="fragment"> 2268<div id="qwebr-insertion-location-9"></div> 2269<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2270<div style="text-align: center;"> 2271<p><span style="font-size: 70%; color: #9c9c9c;">Now, find the median value of <code>iris$Petal.Width</code> while weaving in some crude annotations.</span></p> 2272</div> 2273</div> 2274<div class="fragment"> 2275<div style="text-align: center; margin-top: 30px; font-size: 90%;"> 2276<p>For more elaborate exposition, consider using <a href="https://rmarkdown.rstudio.com/" class="external" target="_blank">RMarkdown</a> or <a href="https://quarto.org/" class="external" target="_blank">Quarto</a> to generate <span style="color: #5d3c85;"><span class="math inline">\LaTeX</span></span>, <code>.docx</code>, <code>.html</code> and <code>.ipynb</code> documents within <svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg>.</p> 2277</div> 2278</div> 2279<div class="scrollable-note"> 2280<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2281</div> 2282</section></section> 2283<section> 2284<section id="exercise-i" class="title-slide slide level1 center" data-background-color="#43464B"> 2285<h1>Exercise I</h1> 2286 2287</section> 2288<section id="four-simple-tasks" class="slide level2 scrollable"> 2289<h2>Four Simple Tasks</h2> 2290<div style="margin-top: 20px;"> 2291 2292</div> 2293<div class="fragment"> 2294<ol type="1"> 2295<li>Fire up RStudio and run the following codeâ</li> 2296</ol> 2297<div id="qwebr-insertion-location-10"></div> 2298<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2299</div> 2300<ol start="2" type="1"> 2301<li class="fragment"><p>Store <code>penguins</code> as a new object named <code>penguins_week6.</code></p></li> 2302<li class="fragment"><p>Calculate the mean of <code>bill_length_mm</code> in the dataset.</p></li> 2303<li class="fragment"><p>How many male and female penguins are in <code>penguins_week6</code>? Use the <code>table</code> function to find outâand add some annotations, too.</p></li> 2304</ol> 2305</section></section> 2306<section> 2307<section id="introduction-to-dplyr-rows" class="title-slide slide level1 center" data-background-color="#43464B"> 2308<h1>Introduction to <span class="white-text"><code>dplyr</code></span>â<br>Rows</h1> 2309 2310</section> 2311<section id="a-reminder" class="slide level2"> 2312<h2>A Reminder</h2> 2313<h4 id="the-pipe-operator"><span style="color:#9c9c9c;">The Pipe Operator</span></h4> 2314<div style="text-align: center;
2314 margin-top: 1px;"> 2315<p>The pipe operator (<code>|></code> in base <svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg>) will help us chain together a series of <code>dplyr</code> verbs as we manipulate our data frames.</p> 2316</div> 2317<div class="fragment"> 2318<div id="qwebr-insertion-location-11"></div> 2319<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2320</div> 2321<div class="scrollable-note"> 2322<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2323</div> 2324</section> 2325<section id="dplyrfilter" class="slide level2"> 2326<h2><code>dplyr::filter()</code></h2> 2327<div style="text-align: center; margin-top: 40px;"> 2328<p>The <code>filter()</code> function allows us to zoom-in on our observations of interest based on column values.</p> 2329</div> 2330<div class="fragment"> 2331<div id="qwebr-insertion-location-12"></div> 2332<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2333</div> 2334<div class="fragment"> 2335<div style="text-align: center;"> 2336<p><span style="font-size: 70%; color: #9c9c9c;">Logical vectors are often used to streamline the âfiltrationâ process.</span></p> 2337</div> 2338<div id="qwebr-insertion-location-13"></div> 2339<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2340</div> 2341<div class="fragment"> 2342<div style="text-align: center;"> 2343<p><span style="font-size: 70%; color: #9c9c9c;">
2343We can use string patterns in character vectors to make life easier, too.</span></p> 2344</div> 2345<div id="qwebr-insertion-location-14"></div> 2346<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2347</div> 2348<div class="scrollable-note"> 2349<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2350</div> 2351</section> 2352<section id="dplyrarrange" class="slide level2"> 2353<h2><code>dplyr::arrange()</code></h2> 2354<div style="text-align: center; margin-top: 40px;"> 2355<p>The <code>arrange()</code> function allows us to modifyâor have fine control overâthe <em>order</em> of our observations based on column values.</p> 2356</div> 2357<div class="fragment"> 2358<div id="qwebr-insertion-location-15"></div> 2359<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2360</div> 2361<div class="fragment"> 2362<div style="text-align: center;"> 2363<p><span style="font-size: 70%; color: #9c9c9c;">We can arrange our rows using multiple variables.</span></p> 2364</div> 2365<div id="qwebr-insertion-location-16"></div> 2366<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2367</div> 2368<div class="fragment"> 2369<div style="text-align: center;"> 2370<p><span style="font-size: 70%; color: #9c9c9c;">We can organize rows in descending order, too.</span></p> 2371</div> 2372<div id="qwebr-insertion-location-17"></div> 2373<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2374</div> 2375<div class="scrollable-note"> 2376<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2377</div> 2378</section> 2379<section id="dplyrdistinct" class="slide level2"> 2380<h2><code>dplyr::distinct()</code></h2> 2381<div style="text-align: center; margin-top: 40px;"> 2382<p>Calling the <code>distinct()</code> function returns all the unique rows or values in a dataset vis-Ã -vis specific variables or their combinations.</p> 2383</div> 2384<div class="fragment"> 2385<div style="text-align: center;"> 2386<p><span style="font-size: 70%; color: #9c9c9c;">Here are the distinct values of the <code>year</code> variable in <code>palmerpenguins::penguins</code>:</span></p> 2387</div> 2388<div id="qwebr-insertion-location-18"></div> 2389<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2390</div> 2391<div class="fragment"> 2392<div style="text-align: center;"> 2393<p><span style="font-size: 70%; color: #9c9c9c;">
2393We can isolate unique <code>species</code> and <code>island</code> pairs, too.</span></p> 2394</div> 2395<div id="qwebr-insertion-location-19"></div> 2396<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2397</div> 2398<div class="fragment"> 2399<div style="text-align: center;"> 2400<p><span style="font-size: 70%; color: #9c9c9c;"><code>distinct()</code> is helpful for removing âredundantâ information or extraneous rows.</span></p> 2401</div> 2402<div id="qwebr-insertion-location-20"></div> 2403<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2404</div> 2405<div class="scrollable-note"> 2406<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2407</div> 2408</section></section> 2409<section> 2410<section id="introduction-to-dplyr-columns" class="title-slide slide level1 center" data-background-color="#43464B"> 2411<h1>Introduction to <span class="white-text"><code>dplyr</code></span>â<br>Columns</h1> 2412 2413</section> 2414<section id="dplyrmutate" class="slide level2"> 2415<h2><code>dplyr::mutate()</code></h2> 2416<div style="text-align: center; margin-top: 30px; font-size: 91%;"> 2417<p>The <code>mutate()</code> function lets us create new variables or modify existing columns. <span style="text-decoration: underline; text-decoration-color: #5d3c85;"><em>Generally</em></span>, this is achieved by manipulating the variables in our data.</p> 2418</div> 2419<div class="fragment"> 2420<div style="text-align: center;"> 2421<p><span style="font-size: 70%; color: #9c9c9c;">Create a new variable for population in 1000s.</span></p> 2422</div> 2423<div id="qwebr-insertion-location-21"></div> 2424<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2425</div> 2426<div class="fragment"> 2427<div style="text-align: center;"> 2428<p><span style="font-size: 70%; color: #9c9c9c;">Logical vectors are useful for generating new variables.</span></p> 2429</div> 2430<div id="qwebr-insertion-location-22"></div> 2431<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2432</div> 2433<div class="scrollable-note"> 2434<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2435</div> 2436</section> 2437<section id="dplyrselect" class="slide level2"> 2438<h2><code>dplyr::select()</code></h2> 2439<div style="text-align: center; margin-top: 30px;"> 2440<p>The <code>select()</code> function lets us home-in on our variables of interest.</p> 2441</div> 2442<div class="fragment"> 2443<div style="text-align: center;"> 2444<p><span style="font-size: 70%; color: #9c9c9c;">
2444We can provide (and modify) column names or positions.</span></p> 2445</div> 2446<div id="qwebr-insertion-location-23"></div> 2447<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2448</div> 2449<div class="fragment"> 2450<div style="text-align: center;"> 2451<p><span style="font-size: 70%; color: #9c9c9c;">We can use helper functions when variables are legion.</span></p> 2452</div> 2453<div id="qwebr-insertion-location-24"></div> 2454<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2455</div> 2456<div class="fragment"> 2457<div style="text-align: center;"> 2458<p><span style="font-size: 70%; color: #9c9c9c;">How can we <span style="color: white; background-color: #5d3c85; padding: 1px 5px;"><strong>remove</strong></span> the first three columns?</span></p> 2459</div> 2460<div id="qwebr-insertion-location-25"></div> 2461<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2462</div> 2463<div class="scrollable-note"> 2464<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2465</div> 2466</section> 2467<section id="dplyrrename" class="slide level2"> 2468<h2><code>dplyr::rename()</code></h2> 2469<div style="text-align: center; margin-top: 60px;"> 2470<p>The <code>rename()</code> function allows us to rename variables without adjusting the dimensions of our data frame.</p> 2471</div> 2472<div class="fragment"> 2473<div style="text-align: center;"> 2474<p><span style="font-size: 70%; color: #9c9c9c;">We can rename columns by specifying variable names as follows: <code>new = old</code>.</span></p> 2475</div> 2476<div id="qwebr-insertion-location-26"></div> 2477<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2478</div> 2479<div class="fragment"> 2480<div style="text-align: center;"> 2481<p><span style="font-size: 70%; color: #9c9c9c;">We can also use column positions to point to the variables weâd like to rename:</span></p> 2482</div> 2483<div id="qwebr-insertion-location-27"></div> 2484<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2485</div> 2486<div class="scrollable-note"> 2487<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2488</div> 2489</section> 2490<section id="dplyrrelocate" class="slide level2"> 2491<h2><code>dplyr::relocate()</code></h2> 2492<div style="text-align: center; margin-top: 40px;"> 2493<p>The <code>relocate()</code> function allows us to move our columns around.</p> 2494</div> 2495<div class="fragment"> 2496<div style="text-align: center;"> 2497<p><span style="font-size: 70%; color: #9c9c9c;">
2497Hereâs how we can move a few columns to the âfront.â</span></p> 2498</div> 2499<div id="qwebr-insertion-location-28"></div> 2500<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2501</div> 2502<div class="fragment"> 2503<div style="text-align: center;"> 2504<p><span style="font-size: 70%; color: #9c9c9c;">We can specify <em>where</em> we want columns relocated.</span></p> 2505</div> 2506<div id="qwebr-insertion-location-29"></div> 2507<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2508</div> 2509<div class="fragment"> 2510<div style="text-align: center;"> 2511<p><span style="font-size: 70%; color: #9c9c9c;">Helper functions can, well, be quite helpful.</span></p> 2512</div> 2513<div id="qwebr-insertion-location-30"></div> 2514<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2515</div> 2516<div class="scrollable-note"> 2517<p><span style="font-size: 75%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2518</div> 2519</section></section> 2520<section> 2521<section id="exercise-ii" class="title-slide slide level1 center" data-background-color="#43464B"> 2522<h1>Exercise II</h1> 2523 2524</section> 2525<section id="the-varieties-of-democracy" class="slide level2"> 2526<h2>The Varieties of Democracy</h2> 2527<div style="text-align: center; font-size: 80%; margin-top: 30px; margin-bottom: 20px;"> 2528<p>For the rest of todayâs session, weâll work with data from the <span style="color: white; background-color: #5d3c85; padding: 1px 5px;"><em>Varieties of Democracy Project</em></span> <span class="citation" data-cites="Coppedge2024">(<a href="#/references" role="doc-biblioref" onclick="">Coppedge et al. 2025</a>)</span>. You can access the codebook for V-Dem 15 below:</p> 2529</div> 2530<p align="center"> 2531<iframe class="iframe" src="data/vdem_15_codebook.pdf" height="450" width="1040" style="border: 1px solid #2e3846;"> 2532</iframe> 2533</p> 2534<div style="text-align: center; font-size: 80%; margin-top:-40px"> 2535<p><a href="https://www.v-dem.net/documents/55/codebook.pdf" class="external" target="_blank">Full Page</a></p> 2536</div> 2537</section> 2538<section id="the-varieties-of-democracy-1" class="slide level2 scrollable"> 2539<h2>The Varieties of Democracy</h2> 2540<h4 id="your-tasks"><span style="color:#9c9c9c;">Your Tasks</span></h4> 2541<div style="margin-top: 20px;"> 2542 2543</div> 2544<div class="fragment"> 2545<ol type="1"> 2546<li>Fire up RStudio and run the following codeâ</li> 2547</ol> 2548<div class="cell"> 2549<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href=""></a><span class="fu">install.packages</span>(<span class="st">"devtools"</span>)</span> 2550<span id="cb1-2"><a href=""></a></span> 2551<span id="cb1-3"><a href=""></a>devtools<span class="sc">::</span><span class="fu">install_github</span>(<span class="st">"vdeminstitute/vdemdata"</span>)</span> 2552<span id="cb1-4"><a href=""></a></span>
2553<span id="cb1-5"><a href=""></a><span class="fu">library</span>(tidyverse)</span> 2554<span id="cb1-6"><a href=""></a></span> 2555<span id="cb1-7"><a href=""></a>vdem <span class="ot"><-</span> vdemdata<span class="sc">::</span>vdem <span class="sc">|></span> <span class="fu">as_tibble</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 2556</div> 2557<div style="text-align: center; font-size: 70%; color: #9c9c9c;"> 2558<p>Alternatively, you can access the data <a href="https://www.v-dem.net/data/the-v-dem-dataset/" class="external" target="_blank">here</a>.</p> 2559</div> 2560</div> 2561<div class="fragment"> 2562<ol start="2" type="1"> 2563<li>Use the <code>dplyr</code> verbs we discussed today to heavily modify the datasetâsay, by isolating specific columns, years, or countries of interest before generating new variables.</li> 2564</ol> 2565</div> 2566</section></section> 2567<section> 2568<section id="data-wrangling-ii-october-8th" class="title-slide slide level1 center" data-background-color="#43464B"> 2569<h1>Data Wrangling IIâ<br>October 8<span style="font-size: 70%;"><sup>th</sup></span></h1> 2570 2571</section> 2572<section id="a-brief-update" class="slide level2"> 2573<h2>A Brief Update</h2> 2574<div style="margin-top: 90px; text-align: center;"> 2575<div class="callout callout-important callout-titled callout-style-default"> 2576<div class="callout-body"> 2577<div class="callout-title"> 2578<div class="callout-icon-container"> 2579<i class="callout-icon"></i> 2580</div> 2581<p><strong>Our Syllabus Will Change</strong></p> 2582</div> 2583<div class="callout-content"> 2584<p>Iâll be updating the syllabus over the mid-semester break. Specifically, I willâin all likelihoodâ<span style="color: white; background-color: #5d3c85; padding: 1px 5px;"><strong>extend the deadline for your first coding assignment</strong></span>.</p> 2585</div> 2586</div> 2587</div> 2588</div> 2589</section> 2590<section id="a-brief-update-1" class="slide level2"> 2591<h2>A Brief Update</h2> 2592<div class="centre-text"> 2593<p>More information about the first coding assignment<br>will be provided <span style="text-decoration: underline; text-decoration-color: #5d3c85;">soon</span>.</p> 2594</div> 2595</section> 2596<section id="a-brief-update-2" class="slide level2"> 2597<h2>A Brief Update</h2> 2598<h4 id="mid-semester-break"><span style="color:#a9a9a9;">Mid-Semester Break</span></h4> 2599<div style="margin-top: 40px; text-align: center;"> 2600<div class="callout callout-warning callout-titled callout-style-default"> 2601<div class="callout-body"> 2602<div class="callout-title"> 2603<div class="callout-icon-container"> 2604<i class="callout-icon"></i> 2605</div> 2606<p><strong>Mid-Semester Break</strong></p> 2607</div> 2608<div class="callout-content"> 2609<p>The mid-semester break is upon us. Ergo, we <span style="text-decoration: underline; text-decoration-color: #5d3c85;"><strong>do not</strong></span> have class on <span style="text-decoration: underline; text-decoration-color: #5d3c85;"><strong>Monday</strong></span>.</p> 2610</div> 2611</div> 2612</div> 2613<div class="fragment"> 2614<p><span style="color: white; background-color: #5d3c85; padding: 1px 5px;"><strong><em>Please, do not show up on Monday</em>.</strong></span></p> 2615</div> 2616</div> 2617</section> 2618<section id="some-resources" class="slide level2"> 2619<h2>Some Resources</h2> 2620<h4 id="using-learnr"><span style="color:#a9a9a9;">Using <a href="https://rstudio.github.io/learnr/articles/examples.html" class="external" target="_blank"><code>learnr</code></a></span></h4> 2621<iframe width="100%" height="450" src="https://rstudio.github.io/learnr/articles/examples.html"> 2622</iframe> 2623</section> 2624<section id="some-resources-1" class="slide level2"> 2625<h2>Some Resources</h2> 2626<h4 id="via-primers"><span style="color:#a9a9a9;">via <a href="https://r-primers.andrewheiss.com/" class="external" target="_blank"><svg aria-hidden="true" role="img" viewbox="0 0 581 512" style="height:1em;width:1.13em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:currentColor;overflow:visible;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> Primers</a></span></h4> 2627<div style="margin-top: 30px;"> 2628 2629</div> 2630<iframe width="100%" height="450" src="https://r-primers.andrewheiss.com/"> 2631</iframe> 2632</section> 2633<section id="some-resources-2" class="slide level2"> 2634<h2>Some Resources</h2> 2635<h4 id="cloning-a-repository-via-simplified"><span style="color:#a9a9a9;">Cloning a Repository via <svg aria-hidden="true" role="img" viewbox="0 0 496 512" style="height:1em;width:0.97em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> (Simplified)</span></h4> 2636<iframe data-external="1" src="https://www.youtube.com/embed/rEbYhq4wyFA" width="100%" height="75%" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe> 2637</section> 2638<section id="a-broad-question" class="slide level2"> 2639<h2>A Broad Question</h2> 2640<div class="centre-text"> 2641<p>With the arrival of ChatGPT (and its analogues),<br>why learn how to code?</p> 2642</div> 2643</section></section> 2644<section> 2645<section id="introduction-to-dplyr-groups" class="title-slide slide level1 center" data-background-color="#43464B"> 2646<h1>Introduction to <span class="white-text"><code>dplyr</code></span>â<br>Groups</h1> 2647 2648</section> 2649<section id="dplyrgroup_by" class="slide level2"> 2650<h2><code>dplyr::group_by()</code></h2> 2651<div style="text-align: center; margin-top: 45px;"> 2652<p>The <code>group_by()</code> function allows us to <em>group</em> our data before performing additional operations or transformations.</p> 2653</div> 2654<div class="fragment"> 2655<div style="text-align: center;"> 2656<p><span style="font-size: 70%; color: #9c9c9c;">Whatâs weird about this code?</span></p> 2657</div> 2658<div id="qwebr-insertion-location-31"></div> 2659<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2660</div> 2661<div class="fragment"> 2662<div style="text-align: center;"> 2663<p><span style="font-size: 70%; color: #9c9c9c;">Crucially, we can apply <code>group_by()</code> to more than one column.</span></p> 2664</div> 2665<div id="qwebr-insertion-location-32"></div> 2666<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2667</div> 2668<div class="scrollable-note"> 2669<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2670</div> 2671</section> 2672<section id="dplyrsummarise" class="slide level2"> 2673<h2><code>dplyr::summarise()</code></h2> 2674<div style="text-align: center; margin-top: 15px;"> 2675<p>We can call the <code>summarize()</code> functionâor <code>summarise()</code>âto easily compute summary statistics at the group level.</p> 2676</div> 2677<div class="fragment"> 2678<div style="text-align: center;"> 2679<p><span style="font-size: 70%; color: #9c9c9c;">What do we need to change before the code can run smoothly?</span></p> 2680</div> 2681<div id="qwebr-insertion-location-33"></div> 2682<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2683</div> 2684<div class="fragment"> 2685<div style="text-align: center;"> 2686<p><span style="font-size: 70%; color: #9c9c9c;">
2686We can generate summary statistics by group combinations (or group <span class="math inline">x</span> group interactions).</span></p> 2687</div> 2688<div id="qwebr-insertion-location-34"></div> 2689<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2690</div> 2691<div class="fragment"> 2692<div style="text-align: center;"> 2693<p><span style="font-size: 70%; color: #9c9c9c;">As of <code>dplyr 1.10</code>, we can use the <code>.by</code> argument for âper-operationâ grouping.</span></p> 2694</div> 2695<div id="qwebr-insertion-location-35"></div> 2696<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2697</div> 2698<div class="scrollable-note"> 2699<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2700</div> 2701</section> 2702<section id="dplyrslice" class="slide level2"> 2703<h2><code>dplyr::slice()</code></h2> 2704<div style="text-align: center; margin-top: 10px;"> 2705<p>The <code>slice()</code> function allows us to extract observations of interest.</p> 2706</div> 2707<div class="fragment"> 2708<div style="text-align: center;"> 2709<p><span style="font-size: 70%; color: #9c9c9c;">Here, we isolate the first (or <code># last</code>) two rows for each continent in <code>gapminder</code>.</span></p> 2710</div> 2711<div id="qwebr-insertion-location-36"></div> 2712<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2713</div> 2714<div class="fragment"> 2715<div style="text-align: center;"> 2716<p><span style="font-size: 70%; color: #9c9c9c;"><code>slice_min()</code> and <code>slice_max()</code> allow us to isolate the minimum or maximum values of column <span class="math inline">x</span>.</span></p> 2717</div> 2718<div id="qwebr-insertion-location-37"></div> 2719<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2720</div> 2721<div class="fragment"> 2722<div style="text-align: center;"> 2723<p><span style="font-size: 70%; color: #9c9c9c;">The <code>slice_sample()</code> function can be used to randomly draw from our (grouped or ungrouped) data.</span></p> 2724</div> 2725<div id="qwebr-insertion-location-38"></div> 2726<noscript>Please enable JavaScript to experience the dynamic code cell content on this page.</noscript> 2727</div> 2728<div class="scrollable-note"> 2729<p><span style="font-size: 80%;"><strong>Note</strong>: Keep clicking <svg aria-hidden="true" role="img" viewbox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"></path></svg> or the space bar on your <svg aria-hidden="true" role="img" viewbox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M64 112c-8.8 0-16 7.2-16 16V384c0 8.8 7.2 16 16 16H512c8.8 0 16-7.2 16-16V128c0-8.8-7.2-16-16-16H64zM0 128C0 92.7 28.7 64 64 64H512c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM176 320H400c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm-72-72c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H120c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H200c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H280c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H360c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16zm64 96c0-8.8 7.2-16 16-16h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V248zm16-96h16c8.8 0 16 7.2 16 16v16c0 8.8-7.2 16-16 16H440c-8.8 0-16-7.2-16-16V168c0-8.8 7.2-16 16-16z"></path></svg> to advance through the slide deck.</span></p> 2730</div> 2731</section> 2732<section id="an-fyi" class="slide level2"> 2733<h2>An FYI</h2> 2734<div style="margin-top: 90px; text-align: center;"> 2735<div class="callout callout-tip callout-titled callout-style-default"> 2736<div class="callout-body"> 2737<div class="callout-title"> 2738<div class="callout-icon-container"> 2739<i class="callout-icon"></i> 2740</div> 2741<p><strong>Note</strong></p> 2742</div> 2743<div class="callout-content"> 2744<p>The last two verbsâi.e., <code>summarize()</code> and <code>slice()</code>âcan be applied to <em>ungrouped</em> data as well. Whatâs more, the other verbs we encountered on Mondayâe.g., <code>filter()</code> or <code>mutate()</code>âcan <em>also</em> be used to manipulate grouped data.</p> 2745</div> 2746</div> 2747</div> 2748</div> 2749</section></section> 2750<section> 2751<section id="return-to-v-dem" class="title-slide slide level1 center" data-background-color="#43464B"> 2752<h1>Return to V-Dem</h1> 2753 2754</section> 2755<section id="todays-exercise" class="slide level2"> 2756<h2>Todayâs Exercise</h2> 2757<div style="text-align: center; margin-top: 20px; font-size: 95%;"> 2758<p>Manipulate your V-Dem data frame so that it looks like this:</p> 2759</div> 2760<div style="text-align: center; margin-top: 20px; font-size: 95%;"> 2761<div class="centered-code"> 2762<div class="shrinker"> 2763<div class="cell"> 2764<div class="cell-output cell-output-stdout"> 2765<pre><code># A tibble: 75 Ã 8 2766 country year electoral electoral_global_avg liberal participatory 2767 <chr> <dbl> <dbl> <dbl> <dbl> <dbl> 2768 1 Canada 2000 0.843 0.491 0.766 0.594 2769 2 Canada 2001 0.838 0.494 0.76 0.587 2770 3 Canada 2002 0.831 0.505 0.753 0.578
2771 4 Canada 2003 0.831 0.513 0.753 0.574 2772 5 Canada 2004 0.83 0.513 0.758 0.571 2773 6 Canada 2005 0.829 0.518 0.756 0.571 2774 7 Canada 2006 0.834 0.521 0.765 0.571 2775 8 Canada 2007 0.834 0.517 0.766 0.572 2776 9 Canada 2008 0.832 0.521 0.762 0.57 277710 Canada 2009 0.833 0.523 0.764 0.57 2778# â¹ 65 more rows 2779# â¹ 2 more variables: deliberative <dbl>, egalitarian <dbl></code></pre> 2780</div> 2781</div> 2782</div> 2783</div> 2784<div class="fragment"> 2785<p>You can access the <code>can_mex_usa</code> data frame via <a href="https://github.com/sakeefkarim/soci-269-f25" class="external" target="_blank">GitHub <svg aria-hidden="true" role="img" viewbox="0 0 496 512" style="height:1em;width:0.97em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg></a> or by copyingâand executingâthe following line:</p> 2786<div class="cell"> 2787<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href=""></a><span class="fu">readRDS</span>(<span class="fu">url</span>(<span class="st">"https://github.com/sakeefkarim/soci-269-f25/raw/refs/heads/main/data/week%206/can_mex_usa.rds?nocache=1"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 2788</div> 2789<div class="scrollable-note"> 2790<p><span style="font-size: 80%;"><strong>Note</strong>: Need a hint? Skip to the next slide.</span></p> 2791</div> 2792</div> 2793</div> 2794</section> 2795<section id="todays-exercise-1" class="slide level2"> 2796<h2>Todayâs Exercise</h2> 2797<h4 id="a-hint-some-more-work"><span style="color:#9c9c9c;">A Hint & Some More Work</span></h4> 2798<div class="shrinker-super-plus"> 2799<div class="panel-tabset"> 2800<ul id="tabset-1" class="panel-tabset-tabby"><li><a data-tabby-default="" href="#tabset-1-1">A Hint</a></li><li><a href="#tabset-1-2">Done?</a></li></ul> 2801<div class="tab-content"> 2802<div id="tabset-1-1"> 2803<div style="text-align: center;"> 2804<p>This character vector should be of interest:</p> 2805<div class="cell styled-output"> 2806<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href=""></a>high_level <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"v2x_polyarchy"</span>, </span> 2807<span id="cb4-2"><a href=""></a> <span class="st">"v2x_libdem"</span>,</span> 2808<span id="cb4-3"><a href=""></a> <span class="st">
2808"v2x_partipdem"</span>, </span> 2809<span id="cb4-4"><a href=""></a> <span class="st">"v2x_delibdem"</span>, </span> 2810<span id="cb4-5"><a href=""></a> <span class="st">"v2x_egaldem"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 2811</div> 2812</div> 2813</div> 2814<div id="tabset-1-2"> 2815<div style="text-align: center;"> 2816<p>Are you done? Congrats! Hereâs some more data to explore <span class="citation" data-cites="gssr">(cf. <a href="#/references" role="doc-biblioref" onclick="">Healy 2023</a>)</span>â</p> 2817<div class="cell"> 2818<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href=""></a><span class="fu">readRDS</span>(<span class="fu">url</span>(<span class="st">"https://github.com/sakeefkarim/soci-269-f25/blob/main/data/week%206/gss_2010.rds"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 2819</div> 2820<p>Explore the variables here:</p> 2821<div class="cell"> 2822<div class="cell-output-display"> 2823<div class="reactable html-widget html-fill-item" id="htmlwidget-8801500b4be140ce881f" style="width:auto;height:auto;"></div>
2824<script type="application/json" data-for="htmlwidget-8801500b4be140ce881f">{"x":{"tag":{"name":"Reactable","attribs":{"data":{"Indicator":["year","id","wrkstat","hrs1","hrs2","evwork","wrkslf","wrkgovt","occ80","prestg80","indus80","indus07","occonet","found","occ10","occindv","occstatus","occtag","prestg10","prestg105plus","indus10","indstatus","indtag","marital","divorce","widowed","spwrksta","sphrs1","sphrs2","spevwork","spwrkslf","spocc80","sppres80","spind80","spocc10","spoccindv","spoccstatus","spocctag","sppres10","sppres105plus","spind10","spindstatus","spindtag","pawrkslf","paocc80","papres80","paind80","paocc10","paoccindv","paoccstatus","paocctag","papres10","papres105plus","paind10","paindstatus","paindtag","maocc80","mapres80","mawrkslf","maind80","maocc10","maoccindv","maoccstatus","maocctag","mapres10","mapres105plus","maind10","maindstatus","maindtag","sibs","childs","age","agekdbrn","educ","paeduc","maeduc","speduc","degree","padeg","madeg","spdeg","sex","race","res16","reg16","mobile16","family16","famdif16","mawrkgrw","incom16","born","parborn","granborn","hompop","babies","preteen","teens","adults","unrelat","earnrs","income","rincome","income06","rincom06","region","xnorcsiz","srcbelt","size","partyid","vote04","pres04","if04who","vote08","pres08","if08who","polviews","natspac","natenvir","natheal","natcity","natcrime","natdrug","nateduc","natrace","natarms","nataid","natfare","natroad","natsoc","natmass","natpark","natchld","natsci","
2824natenrgy","natspacy","natenviy","nathealy","natcityy","natcrimy","natdrugy","nateducy","natracey","natarmsy","nataidy","natfarey","eqwlth","tax","spkath","colath","libath","spkrac","colrac","librac","spkcom","colcom","libcom","spkmil","colmil","libmil","spkhomo","colhomo","libhomo","spkmslm","colmslm","libmslm","cappun","gunlaw","courts","grass","relig","denom","other","jew","fund","attend","reliten","postlife","pray","popespks","relig16","denom16","oth16","jew16","fund16","sprel","spden","spother","spjew","spfund","prayer","bible","racopen","raclive","racpres","affrmact","wrkwayup","closeblk","closewht","happy","hapmar","health","life","helpful","fair","trust","confinan","conbus","conclerg","coneduc","confed","conlabor","conpress","conmedic","contv","conjudge","consci","conlegis","conarmy","obey","popular","thnkself","workhard","helpoth","socrel","socommun","socfrend","socbar","aged","weekswrk","partfull","joblose","jobfind","satjob","richwork","class","rank","satfin","finalter","finrela","wksub","wksubs","wksup","wksups","unemp","union","getahead","parsol","kidssol","fepres","fepol","abdefect","abnomore","abhlth","abpoor","abrape","absingle","abany","chldidel","pillok","sexeduc","divlaw","premarsx","teensex","xmarsex","homosex","pornlaw","xmovie","spanking","letdie1","suicide1","suicide2","suicide3","suicide4","polhitok","polabuse","polmurdr","polescap","polattak","fear","owngun","pistol","shotgun","rifle","rowngun","hunt","news","tvhours","phone","coop","comprend","form","fechld","fepresch","fefam","racdif1","racdif2","racdif3","racdif4","helppoor","helpnot","helpsick","helpblk","god","reborn","savesoul","punsin","blkwhite","rotapple","permoral","wlthwhts","wlthblks","workwhts","workblks","intlwhts","intlblks","liveblks","livewhts","marblk","marasian","marhisp","marwht","racwork","discaff","fejobaff","discaffm","discaffw","fehire","rellife","relpersn","sprtprsn","relexp","othlang","othlang1","othlang2","spklang","betrlang","compuse","webmob","emailmin","emailhr","usewww","wwwhr","wwwmin","wrktype","yearsjob","waypaid","wrksched","moredays","mustwork","chngtme","wrkhome","whywkhme","famwkoff","wkvsfam","famvswk","hrsrelax","secondwk","learnnew","workfast","workdiff","overwork","knowwhat","myskills","respect","trustman","safetywk","safefrst","teamsafe","safehlth","proudemp","prodctiv","wksmooth","trdunion","partteam","wkdecide","toofewwk","promteok","opdevel","hlpequip","haveinfo","wkfreedm","fringeok","supcares","condemnd","promtefr","cowrkint","jobsecok","suphelp","wrktime","cowrkhlp","manvsemp","hvylift","handmove","wkpraise","fairearn","rincblls","laidoff","jobfind1","trynewjb","wkageism","wkracism","wksexism","wkharsex","wkharoth","health1","physhlth","mntlhlth","hlthdays","usedup","backpain","painarms","hurtatwk","spvtrfair","strredpg","phyeffrt","slpprblm","satjob1","workfor","ownstock","stockops","numemps","relneg","newsfrom","scifrom","seeksci","nextgen","toofast","advfront","astrolgy","astrosci","scibnfts","balpos","balneg","scistudy","scitext","expdesgn","exptext","odds1","odds2","hotcore","radioact","boyorgrl","lasers","electron","viruses","bigbang","condrift","evolved","earthsun","solarrev","tomatoes","intrhome","coldeg1","majorcol","colsci","colscinm","hsmath","hsbio","hschem","hsphys","gwsci","gwpol","gwbiz","sciagrgw","sciinfgw","polinfgw","bizinfgw","scibstgw","polbstgw","bizbstgw","scmed","screlig","scpol","medagrsc","medinfsc","relinfsc","polinfsc","medbstsc","relbstsc","polbstsc","scresrch","txeco","txbiz","txpol","ecoagree","ecoinftx","bizinftx","polinftx","ecobsttx","bizbsttx","polbsttx","knwpolar","polaryr1","polaryr2","polaryr3","polaryr4","polaryr5","polaryr6","polaryr7","polaryr8","icesheet","nosun","inuit","huntbear","icecaps","comorsci","extinct","sealevel","penguins","inuitway","noicecap","caremost","nanotech","nanoknw1","nanoknw2","nanowill","nanoben","nanoharm","intintl","intfarm","inteduc","intsci","intecon","inttech","intmed","intspace","intenvir","intmil","morempg","polnuke","biznuke","engnuke","engagrnk","enhinfnk","polinfnk","bizinfnk","engbstnk","polbstnk","bizbstnk","nukeelec","cloning","scinews1","scinews2","scinews3","newsfrmy","scifromy","seeksciy","sciinfgo","numorg","goodlife","goveqinc","marhomo1","meovrwrk","stress","suprvsjb","localnum","relexper","relactiv","privent","postmat1","postmat2","scifaith","harmgood","scigrn","grnecon","harmsgrn","grnprog","grwthelp","grwtharm","grnprice","grntaxes","grnsol","toodifme","ihlpgrn","carsgen","nukegen","indusgen","chemgen","watergen","pubdecid","busdecid","usdoenuf","recycle","chemfree","drivless","grngroup","grnsign","grnmoney","grndemo","popgrwth","impgrn","othssame","grnexagg","genegen","grnintl","ldcgrn","econgrn","topprob1","topprob2","trust5","fair5","grncon","enprbus","enprbfam","knwcause","knowsol","futenrgy","helpharm","grneffme","tempgen1","busgrn","peopgrn","redcehme","h2oless","nobuygrn","letin1a","govdook","polgreed","partners","matesex","frndsex","acqntsex","pikupsex","paidsex","othersex","sexsex","sexfreq","numwomen","nummen","partnrs5","sexsex5","evpaidsx","evstray","condom","relatsex","evidu","idu30","evcrack","crack30","hivtest","hivtest1","hivtest2","sexornt","realinc","realrinc","coninc","conrinc","ethnic","eth1","eth2","eth3","ethnum","hispanic","racecen1","racecen2","racecen3","uscitzn","fu
2824citzn","vetyears","dwelling","dwelown","worda","wordb","wordc","wordd","worde","wordf","wordg","wordh","wordi","wordj","wordsum","relate1","gender1","old1","mar1","away1","where1","relate2","gender2","old2","mar2","away2","where2","relate3","gender3","old3","mar3","away3","where3","relate4","gender4","old4","mar4","away4","where4","relate5","gender5","old5","mar5","away5","where5","relate6","gender6","old6","mar6","away6","where6","relate7","gender7","old7","mar7","away7","where7","relate8","gender8","old8","mar8","relate9","gender9","old9","mar9","relate10","gender10","old10","relate11","gender11","old11","mar11","away11","where11","relate12","gender12","old12","mar12","old13","old14","relhhd1","relhhd2","relhhd3","relhhd4","relhhd5","relhhd6","relhhd7","relhhd8","relhhd9","relhhd10","relhhd11","relhhd12","hefinfo","hhrace","respnum","hhtype","hhtype1","famgen","rplace","rvisitor","visitors","relhh1","relhh2","relhh3","relhh4","relhh5","relhh6","relhh7","relhh8","relhh9","relhh10","relhh11","relhh12","relsp1","relsp2","relsp3","relsp4","relsp5","relsp6","relsp7","relsp8","relsp9","relsp10","relsp11","relsp12","dateintv","isco681","paisc681","maisc681","spisc681","isco88","paisco88","maisco88","spisco88","sei","pasei","masei","spsei","sei10","sei10educ","sei10inc","pasei10","pasei10educ","pasei10inc","masei10","masei10educ","masei10inc","spsei10","spsei10educ","spsei10inc","uswar","uswary","cohort","zodiac","inthisp","intrace1","intrace2","intrace3","whoelse1","whoelse2","whoelse3","whoelse4","whoelse5","whoelse6","feeused","feelevel","lngthinv","intage","intethn","mode","intsex","intyrs","consent","death","version","issp","formwt","sampcode","sample","oversamp","spanself","spaneng","res2006","cshutyp06","cshutyp08","wtss","wtssnr","wtssall","vstrat","vpsu","fileversion"],"Label":["gss year for this respondent","respondent id number","labor force status","number of hours worked last week","number of hours usually work a week","ever work as long as one year","r self-emp or works for somebody","govt or private employee","r's census occupation code (1980)","r's occupational prestige score(1980)","r's industry code (1980)","industry code based on naics 2007","occupation code based on o*net","case was retrievable in 2012","r's census occupation code (2010)","r's occ/ind verbatim retrieved","occ10 coding status","occ10 coding tag","r's occupational prestige score (2010)","r's occupational prestige score using threshold method (2010)","r's industry code (naics 2007)","indus10 coding status","indus10 coding tag","marital status","ever been divorced or separated","ever been widowed","spouse labor force status","number of hrs spouse worked last week","no. of hrs spouse usually works a week","spouse ever work as long as a year","spouse self-emp. or works for somebody","spouse census occupation code (1980)","spouse's occupational prestige score (1980)","spouse's industry code (1980)","spouse census occupation code (2010)","spouse's occ/ind verbatim retrieved","spocc10 coding status","spocc10 coding tag","spouse occupational prestige score (2010)","spouse occupational prestige score using threshold method (2010)","spouse's industry code (naics 2007)","spind10 coding status","spind10 coding tag","father self-emp. or worked for somebody","father's census occupation code (1980)","father's occupational prestige score (1980)","father's industry code (1980)","father's census occupation code (2010)","father's occ/ind verbatim retrieved","paocc10 coding status","paocc10 coding tag","father's occupational prestige score (2010)","father's occupational prestige score using threshold method (2010)","father's industry code (naics 2007)","paind10 coding status","paind10 coding tag","mothers census occupation code (1980)","mothers occupational prestige score (1980)","mother self-emp. or worked for somebody","mothers industry code (1980)","mothers census occupation code (2010)","mothers occ/ind verbatim retrieved","maocc10 coding status","maocc10 coding tag","mothers occupational prestige score (2010)","mothers occupational prestige score using threshold method (2010)","mothers industry code (naics 2007)","maind10 coding status","maind10 coding tag","number of brothers and sisters","number of children","age of respondent","r's age when 1st child born","highest year of school
2824completed","highest year school completed, father","highest year school completed, mother","highest year school completed, spouse","r's highest degree","father's highest degree","mothers highest degree","spouse's highest degree","respondents sex","race of respondent","type of place lived in when 16 yrs old","region of residence, age 16","geographic mobility since age 16","living with parents when 16 yrs old","reason not living with parents","mothers employment when r was 16","r's family income when 16 yrs old","was r born in this country","were r's parents born in this country","how many grandparents born outside u.s.","number of persons in household","household members less than 6 yrs old","household members 6 thru 12 yrs old","household members 13 thru 17 yrs old","household members 18 yrs and older","number in household not related","how many in family earned money","total family income","respondents income","total family income","respondents income","region of interview","expanded norc size code","src beltcode","size of place in 1000s","political party affiliation","did r vote in 2004 election","vote for kerry, bush, nader","who would r has voted for in 2004 election","did r vote in 2008 election","vote obama or mccain","who you would have voted for","think of self as liberal or conservative","space exploration program","improving & protecting environment","improving & protecting nations health","solving problems of big cities","halting rising crime rate","dealing with drug addiction","improving nations education system","improving the conditions of blacks","military, armaments, and defense","foreign aid","welfare","highways and bridges","social security","mass transportation","parks and recreation","assistance for childcare","supporting scientific research","developing alternative energy sources","space exploration:version y","the environment:version y","health:version y","assistance to big cities:version y","law enforcement:version y","drug rehabilitation:version y","education:version y","assistance to blacks:version y","national defense:version y","assistance to other countries:ver y","assistance to the poor:version y","should govt reduce income differences","r's federal income tax","allow anti-religionist to speak","allow anti-religionist to teach","allow anti-religious book in library","allow racist to speak","allow racist to teach","allow racists book in library","allow communist to speak","should communist teacher be fired","allow communists book in library","allow militarist to speak","allow militarist to teach","allow militarists book in library","allow homosexual to speak","allow homosexual to teach","allow homosexuals book in library","allow muslim clergymen preaching hatred of the us","allow anti-american muslim clergymen teaching in college","allow anti-american muslim clergymen's books in library","favor or oppose death penalty for murder","favor or oppose gun permits","courts dealing with criminals","should marijuana be made legal","r's religious preference","specific denomination","other protestant denominations","what sort of jew r is","how fundamentalist is r currently","how often r attends religious services","strength of affiliation","belief in life after death","how often does r pray","pope is infallible on matter's of faith or morals","religion in which raised","denomination in which r was raised","other protestant denominations","what sort of jew r was at age 16","how fundamentalist was r at age 16","spouse's religious preference","specific denomination, spouse","other protestant denominations","what sort of jew is r's spouse currently","how fundamentalist is spouse currently","bible prayer in public schools","feelings about the bible","vote on open housing law","any opp. race in neighborhood","would vote for black president","favor preference in hiring blacks","blacks overcome prejudice without favors","how close feel to blacks","how close feel to whites","general happiness","happiness of marriage","condition of health","is life exciting or dull","people helpful or looking out for selves","people fair or try to take advantage","can people be trusted","confid in banks & financial institutions","confidence in major companies","confidence in organized religion","confidence in education","confid. in exec branch of fed govt","confidence in organized labor","confidence in press","confidence in medicine","confidence in television","confid. in united states supreme court","confidence in scientific community","confidence in congress","confidence in military","to obey","to be well liked or popular","to think for ones self","to work hard","to help others","spend evening with relatives","spend evening with neighbor","spend evening with friends","
2824spend evening at bar","should aged live with their children","weeks r worked last year","was r's work part-time or full-time?","is r likely to lose job","could r find equally good job","work satisfaction","if rich, continue or stop working","subjective class identification","r's self ranking of social position","satisfaction with financial situation","change in financial situation","opinion of family income","does r or spouse have supervisor","does supervisor have supervisor","does r or spouse supervise anyone","does subordinate supervise anyone","ever unemployed in last ten yrs","does r or spouse belong to union","opinion of how people get ahead","r's living standard compared to parents","r's kids living standard compared to r","vote for woman president","women not suited for politics","strong chance of serious defect","married--wants no more children","woman's health seriously endangered","low income--cant afford more children","pregnant as result of rape","not married","abortion if woman wants for any reason","ideal number of children","birth control to teenagers 14-16","sex education in public schools","divorce laws","sex before marriage","sex before marriage:teens 14-16","sex with person other than spouse","homosexual sex relations","feelings about pornography laws","seen x-rated movie in last year","favor spanking to discipline child","allow incurable patients to die","suicide if incurable disease","suicide if bankrupt","suicide if dishonored family","suicide if tired of living","ever approve of police striking citizen","citizen said vulgar or obscene things","citizen questioned as murder suspect","citizen attempting to escape custody","citizen attacking policeman with fists","afraid to walk at night in neighborhood","have gun in home","pistol or revolver in home","shotgun in home","rifle in home","does gun belong to r","does r or spouse hunt","how often does r read newspaper","hours per day watching tv","does r have telephone","r's attitude toward interview","r's understanding of questions","form of split questionnaire asked","mother working doesn't hurt children","preschool kids suffer if mother works","better for man to work, woman tend home","differences due to discrimination","differences due to in-born learning ability","differences due to lack of education","differences due to lack of will","should govt improve standard of living?","should govt do more or less?","should govt help pay for medical care?","should govt aid blacks?","r's confidence in the existence of god","has r ever had a 'born again' experience","tried to convince others to accept jesus","r agrees that sinners must be punished","r agrees right & wrong not black & white","r agrees immoral person corrupts society","r agrees that morality a personal matter","rich - poor","rich - poor","hard working - lazy","hard working - lazy","unintelligent -intelligent","unintelligent - intelligent","neighborhood half black","r favors living in half white neighborhood","close relative marry black","close relative marry asian","close relative marry hispanic","r favor close relative marrying white person","racial makeup of workplace","whites hurt by aff. action","for or against preferential hiring of women","a man won't get a job or promotion","a woman won't get a job or promotion","should hire and promote women","try to carry beliefs into other dealings","r consider self a religious person","r consider self a spiritual person","have religious experience changed life","can r speak language other than english/spanish","what other languages does r speak","what other languages does r speak","how well does r speak other language","which language r speaks more fluent","r use computer","r uses home internet through mobile device","email minutes per week","email hours per week","r use www other than email","www hours per week","www minutes per week","work arrangement at main job","time at current job","how paid in main job","usual work schedule","days per month r work extra hours","mandatory to work extra hours","how often r allowed change schedule","how often r works at home","usual reason r work at home","how hard to take time off","how often job interferes fam life","how often fam life interfere job","hours per day r have to relax","r has job other than main","job requires r to learn new things","job requires r to work fast","r does numerous things on job","r has too much work to do well","r knows what's expected on job","job allows r use of skills","r treated with respect at work","r trust management at work","worker safety priority at work","no shortcuts on worker safety","mgt and employees work together re safety","safety and health condition good at work","r proud to work for employer","work conditions allow productivity","workplace runs in smooth manner","workers need strong unions","r work as part of a team","how often r take part in decisions","how often not enough staff","r's chances for promotion good","opportunity to develop my abilities","enough help and equip to ge the job done","enough info to get the job done","a lot of freedom to decide how to do job","fringe benefits are good","supervisor concerned about welfare","r free from conflicting demands","promotions are handled fairly","coworkers take a personal interest in r","the job security is good","supervisor helpful to r in getting job done","r has enough time to get the job done","coworkers can be relied on when r needs help","relations bw management and employees","r do repeated lifting","r perform forceful hand movements","r is likely to be praised by supervisor","how fair is what r earn on the job","income alone is enough","r was laid off main job last year","how easy for r to find a same job","how likely r make effort for new job next year","r feels discriminated because of age","r feels discriminated because of race","r feels discriminated because of gender","r sexually harassed on the job last 12 months","r threatened on the job last 12 months","r's health in general","days of poor p
2824hysical health past 30 days","days of poor mental health past 30 days","days of activity limitation past 30 days","how often during past month r felt used up","r had back pain in the past 12 months","r had pain in the arms in the past 12 months","number of injuries on the job past 12 months","supervisor is fair","access to stress management","rate physical effort","trouble sleeping last 12 months","job satisfaction in general","r work for whom","r has stock in r's company","r hold any stock options of r's company","number of employee for the self-employed","any turning point when less committed to religion","main source of information about events in the news","main source of information about science and technology","probable source of information about scientific issues","science & tech. give more opportunities to next generation","science makes our way of life change too fast","sci rsch is necessary and should be supported by federal govt","ever read a horoscope or personal astrology report","astrology is scientific","benefits of sci research outweigh harmful results","sci research is strongly in favor of benefits","sci research is strongly in favor of harmful results","r has clear understanding of scientific study","what it means to r to study scientifically","better way to test drug btw control and non-control","why is it better to test drug this way","test of knowledge about probablity1","test of knowledge about probablity2","sci knowledge: the center of earth is very hot","sci knowledge: the center of earth is very hot","sci knowledge: father gene decides sex of baby","sci knowledge: lasers work by focusing sound waves","sci knowledge: electrons are smaller than atoms","sci knowledge: antibiotics kill viruses as well as bacteria","sci knowledge: the universe began with a huge explosion","sci knowledge: the continents have been moving","sci knowledge: human beings developed from animals","sci knowledge: the earth goes around the sun","sci knowledge: how long the earth goes around the sun","regular tomatoes no genes","internet access in r's home","the highest degree r have earned","the field of degree r earned","r has taken any college-level sci course","number of college-level sci courses r have taken","the highest level of math r completed in high school","r ever took a high school biology course","r ever took a high school chemistry course","r ever took a high school physics course","understanding of global warming by environmnt scientists","understanding of global warming by elected officials","understanding of global warming by business leaders","extent of agreement on global warming amg env scientists","influence on global warming policy: environmntal scientists","influence on global warming policy: elected official","influence on global warming policy: business leader","best policy vs narrow interest: environmental scientist","best policy vs narrow interest: elected official","best policy vs narrow interest: business leader","how well medical researcher's understand stem cells","how well religious leaders understand stem cells","how well elected officials understand stem cells","agreement by med researchers on importance of stem cell rsch","influence on funding for stem cell rsch: medical researchers","influence on funding for stem cell rsch: religious leaders","influence on funding for stem cell rsch: elected officials","best policy on stem cell vs narrow interest: med researcher","best policy on stem cell vs narrow interest: relig leader","best policy on stem cell vs narrow interest: elected official","government should fund stem cell research","how well economist knows effect of reducing fed income tax","how well business leader knows effect of reducing fed inc tax","how well elected official knows effect of reducing fed inc tax","agreement by economists on effect of reducing fed inc tax","influence on reducing fed inc taxby economists","influence on reducing fed inc taxby business leaders","influence on reducing fed inc taxby elected officials","best policy vs narrow interest on fed inc tax: economist","best policy vs narrow interest on fed inc tax: business leader","best policy vs narrow interest on fed inc tax: elected official","level of r's information: the north and south poles","intl polar year 07-08:r would watch a tv program","intl polar year 07-08:r would read a newspaper article","intl polar year 07-08:r would read a magazine article","intl polar year 07-08:r would go to museum","intl polar year 07-08:r would watch a feature film","intl polar year 07-08:r would read a book","intl polar year 07-08:r would visit a web site","intl polar year 07-08:r would attend a live lecture","true-false: the north pole is on a sheet of ice","true-false: the sun never shines at the south pole","true-false: inuit live north of the arctic circle","true-false: hunting make polar bear extinct than climate change","polar ice caps got larger or smaller over last 25 yrs","antarctica should be reserved or open","effect of global warming: polar bear's become extinct","effect of global warming: sea level flood coastal areas","antarctic penguins threatened","effect of global warming: inuit no longer follow traditional way of life","effect of global warming: n
2824orthern ice cap melt","most concerned possible effect of global warming","how much r heard about nanotechnology","true-false: nanotechnology manipulate extremely small units","true-false: nanoscale differ from same material at larger scale","benefit of nanotechnology outweigh harmful results","balance will be strongly in favor of the benefits or slightly","balance will be strongly in favor of the benefits or slightly","interested in international issues","interested in farm issues","interested in local school issues","interested in new scientific discoveries","interested in economic issues","interested in technologies","interested in medical discoveries","interested in space exploration","interested in environmental issues","interested in military policy","cars use less gasoline","how well elected official know risk by nuclear power","how well business leader know risk by nuclear power","nuclear engineers understand nuclear power","engineers agree nuclear power","nuclear engineers how much influence","elected officials how much influence","business leaders how much influence","nuclear engineers best for country","elected officials best for country","business leaders best for country","view about nuclear energy","cloning makes identical copy","newspaper printed or online","magazine printed or online","where online get info","where news events info","where get science and technology info","where get science issue news","where online get info","number of people working in organization at all locations","standard of living of r will improve","govmnt should reduce inc differentials","homosexuals have right to marry","men hurt family when focus on work too much","how often does r find work stressful","does r supervise others at work","number of employees: r's work site","turning point in life for religion","how often does r take part in relig activities","private enterprise will solve u.s. problems","highest priority for america","2nd highest priority for america","believe too much in science, not enough faith","modern science does more harm than good","modern science will solve envir probs","worry too much about envir, too little econ","almost everything we do harms envir","worry too much about progress harming envir","amer needs econ grwth to protect envir","econ grwth always harms envir","pay higher prices to help envir?","pay higher taxes to help envir?","accept cut in living stnds to help envir?","too diff to do anything about envir","do what i can to help envir","car pollution danger to envir","nuke power danger to envir","indust air pollution danger to envir","pesticides danger to envir","water pollution danger to envir","govt should let peop decide how to protect envir","govt should let biz decide how to protect envir","u.s. protect environment","recycle cans bottles","buy pesticide free fruits, vegetables","drive less for envir reasons","member of envir group","sign petition on envir issue","give money to envir group","protested for envir issue","earth cannot support population growth","more important in life than save environment","no saving environment unless others do same","environmental threats exaggerated","how dangerous modifying genes in crops","intl agreements for environment problems","poor countries less than rich for environment","economic progress dependent on environment","most important issue for america","next important issue","people can or cannot be trusted","people fair or not","concerned about environment","most important environment problem","problem effect family most","know causes of environment issues","know solutions to environment issues","u.s. energy priorities","way living helps or harms","environment effect everyday life","greenhouse effect danger to envir","u.s. business to protect environment","how get people to protect environment","how often reduce fuel","how often save water","how often avoid products","number of immigrants nowadays should be","we can trust people in govt","most politicians are only for what get out of politics","how many sex partner's r had in last year","was 1 of r's partner's spouse or regular","r had sex with friend last year","r had sex with acquaintance last year","r had sex with casual date last year","r had sex for pay last year","r had sex with some other last year","sex of sex partner's in last year","frequency of sex during last year","number of female sex partner's since 18","number of male sex partner's since 18","how many sex partner's r had in last 5 years","sex of sex partner's last five years","ever have sex paid for or being paid since 18","have sex other than spouse while married","used condom last time","relation to last sex partner","r ever inject drugs","r inject drugs in past 30 days","r ever use crack cocaine","r last use crack cocaine","have you ever been tested for hiv","in what month and year was your last hiv test","where did you have your last hiv test","sexual orientation","family income in constant $","r's income in constant $","fam
2824ily income in constant dollars","respondent income in constant dollars","country of family origin","1st mentioned country of origin","2nd mentioned country of origin","3rd mentioned country of origin","type of response about ethnicity:r","hispanic specified","what is r's race 1st mention","what is r's race 2nd mention","what is r's race 3rd mention","is r us citizen","is r planning/appling for us citizenship or not","years in armed forces","type of structure","does r own or rent home?","word a","word b","word c","word d","word e","word f","word g","word h","word i","word j","number words correct in vocabulary test","relationship of 1st person to household head","gender of 1st person","age of 1st person","marital status of 1st person","is 1st person staying somewhere else now?","where is 1st person staying?","relationship of 2nd person to household head","gender of 2nd person","age of 2nd person","marital status of 2nd person","is 2nd person staying somewhere else now?","where is 2nd person staying?","relationship of 3rd person to household head","gender of 3rd person","age of 3rd person","marital status of 3rd person","is 3rd person staying somewhere else now?","where is 3rd person staying?","relationship of 4th person to household head","gender of 4th person","age of 4th person","marital status of 4th person","is 4th person staying somewhere else now?","where is 4th person staying?","relationship of 5th person to household head","gender of 5th person","age of 5th person","marital status of 5th person","is 5th person staying somewhere else now?","where is 5th person staying?","relationship of 6th person to household head","gender of 6th person","age of 6th person","marital status of 6th person","is 6th person staying somewhere else now?","where is 6th person staying?","relationship of 7th person to household head","gender of 7th person","age of 7th person","marital status of 7th person","is 7th person staying somewhere else now?","where is 7th person staying?","relationship of 8th person to household head","gender of 8th person","age of 8th person","marital status of 8th person","relationship of 9th person to household head","gender of 9th person","age of 9th person","marital status of 9th person","relationship of 10th person to household head","gender of 10th person","age of 1oth person","relation of 11th person (visitor) to head","gender of 11th person (visitor)","age of 11th person (visitor)","marital status of 11th person (visitor)","is 11th person (visitor) staying elsewhere now?","where is 11th person (visitor) staying?","relation of 12th person (visitor) to head","gender of 12th person (visitor)","age of 12th person (visitor)","marital status of 12th person (visitor)","age of 13th person (visitor)","age of 14th person (visitor)","relation of 1st person to household head","relation of 2nd person to household head","relation of 3rd person to household head","relation of 4th person to household head","relation of 5th person to household head","relation of 6th person to household head","relation of 7th person to household head","relation of 8th person to household head","relation of 9th person to household head","relation of 1oth person to household head","relation of 11th person (visitor) to head","relation of 12th person (visitor) to head","number of hef informant","race of household","number in family of r","household type","household type (condensed)","number of family generations in household","r's relationship to household head","is r a visitor?","number of visitor's in household","relationship of person 1 to head of household","relationship of person 2 to head of household","relationship of person 3 to head of household","relationship of person 4 to head of household","relationship of person 5 to head of household","relationship of person 6 to head of household","relationship of person 7 to head of household","relationship of person 8 to head of household","relationship of person 9 to head of household","relationship of person 10 to head of household","relationship of person 11 to head of household","relationship of person 12 to head of household","relationship of person 1 to spouse of househol","relationship of person 2 to spouse of househol","relationship of person 3 to spouse of househol","relationship of person 4 to spouse of househol","relationship of person 5 to spouse of househol","relationship of person 6 to spouse of househol","relationship of person 7 to spouse of househol","relationship of person 8 to spouse of househol","relationship of person 9 to spouse of househol","relationship of person 10 to spouse of househo","relationship of person 11 to spouse of househo","relationship of person 12 to spouse of househo","date of interview","respondent's occupation, 1980 census","r's father's occupation, 1980 census","r's mothers occupation, 1980 census","r's spouse's occupation, 1980 census","respondent's occupation, 1980 census & 1988 isco code","r's father's occupation, 1980 census & 1988 isco code","r's mothers occupation, 1980 census & 1988 isco code","r's spouse's occupation, 1980 census & 1988 isco code","respondent socioeconomic index (1980)","r's father's socioeconomic index (1980)","r's mothers socioeconomic index (1980)","r's spouse's socioeconomic index (1980)","r's socioeconomic index (2010)","percentage of some college educ in occ10 based on acs 2010","percentage of $45k+ earners in occ10 based on acs 2010","r's father's socioeconomic index (2010)","percentage of some college educ in paocc10 based on acs 2010","percentage of $45k+ earners in paocc10 based on acs 2010","r's mother's socioeconomic index (2010)","percentage of some college educ in maocc10 based on acs 2010","percentage of $45k+ earners in maocc10 based on acs 2010","r's spouse's socioeconomic index (2010)","percentage of some college educ in spocc10 based on acs 2010","percentage of $45k+ earners in spocc10 based on acs 2010","expect u.s. in war within 10 years","expect u.s. in world war in 10 years","year of birth","respondents astrological sign","is interviewer spanish, hispanic or latino","interviewer s race1","interviewer s race2","interviewer s race3","presence of others: children under six","presence of others: older children","presence of others: spouse partner","presence of others: other relatives","presence of others: other adults","presence of others: no one","fee given to get case","amount of fees paid","how long was interview","age of interviewer","race of interviewer","interview done in-person or over the phone","sex of interviewer","years of service as an interviewer at norc","participation/recording consent","r's possible vital status as of 2014","version of questionnaire","filter for issp cases","weight deal with experimental randomization","sampling error code","sampling frame and method","weights for black oversamples","if this interview had only been available in english, would you...","interviews conducted in spanish or english","was r living in usa during march-may 2006","during march-may 2006, was r resident in household or institution","during april-june 2008, was r resident in household or institution","weight variable","weight variable","weight variable","variance stratum","variance primary sampling unit","gss data file version"]},"columns":[{"id":"Indicator","name":"Indicator","type":"character"},{"id":"Label","name":"Label","type":"character"}],"filterable":true,"searchable":true,"defaultPageSize":5,"showPageSizeOptions":true,"highlight":true,"theme":{"borderColor":"#dfe2e5","stripedColor":"#f6f8fa","highlightColor":"#b7a5d3","style":{"fontSize":"15px"},"searchInputStyle":{"width":"100%"}},"dataKey":"03fe12cc1e83080d0310da94a861fd13"},"children":[]},"class":"reactR_markup"},"evals":[],"jsHooks":[]}</script>
2824 2825</div> 2826</div> 2827</div> 2828</div> 2829</div> 2830</div> 2831</div> 2832</section></section> 2833<section> 2834<section id="see-you-next-wednesday" class="title-slide slide level1 center" data-background-color="#43464B"> 2835<h1>See You <em>Next</em> Wednesday</h1> 2836 2837</section> 2838<section id="references" class="slide level2 smaller scrollable"> 2839<h2>References</h2> 2840<div style="text-align: center; margin-top: 15px"> 2841 2842</div> 2843<!-- [**Note**: Scroll `<svg aria-hidden="true" role="img" viewBox="0 0 384 512" style="height:1em;width:0.75em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5d3c85;overflow:visible;position:relative;"><path d="M169.4 470.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 370.8 224 64c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 306.7L54.6 265.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg>`{=html} to access the entire bibliography]{style="color: #9c9c9c; font-size:95%;"} --> 2844 2845<div id="refs" class="references csl-bib-body hanging-indent" role="list"> 2846<div id="ref-Coppedge2024" class="csl-entry" role="listitem"> 2847Coppedge, Michael, John Gerring, Carl Henrik Knutsen, Staffan I. Lindberg, Jan Teorell, et al. 2025. <span>â<a href="https://doi.org/10.23696/vdemds25">V-Dem Country-Year Dataset V15</a>.â</span> 2848</div> 2849<div id="ref-gssr" class="csl-entry" role="listitem"> 2850Healy, Kieran Joseph. 2023. <em><a href="http://kjhealy.github.io/gssr"><span class="nocase">gssr</span>: General Social Survey Data for Use in <span>R</span></a></em>. 2851</div> 2852<div id="ref-wickham_r_2023" class="csl-entry" role="listitem"> 2853Wickham, Hadley, Mine Ãetinkaya-Rundel, and Garrett Grolemund. 2023. <em><a href="https://r4ds.hadley.nz/">R for Data Science: Import, Tidy, Transform, Visualize, and Model Data</a></em>. 2nd edition. Sebastopol, CA: OâReilly. 2854</div> 2855</div> 2856</section></section> 2857 </div> 2858 <div class="quarto-auto-generated-content" style="display: none;"> 2859<p><img src="media/amherst seal.png" class="slide-logo"></p> 2860<div class="footer footer-default"> 2861 2862</div> 2863</div></div> 2864 2865
2865<script>window.backupDefine = window.define; window.define = undefined;</script>
2865 2866
2866<script src="index_files/libs/revealjs/dist/reveal.js"></script>
2866 2867 <!-- reveal.js plugins --> 2868
2868<script src="index_files/libs/revealjs/plugin/quarto-line-highlight/line-highlight.js"></script>
2868 2869
2869<script src="index_files/libs/revealjs/plugin/pdf-export/pdfexport.js"></script>
2869 2870
2870<script src="index_files/libs/revealjs/plugin/reveal-menu/menu.js"></script>
2870 2871
2871<script src="index_files/libs/revealjs/plugin/reveal-menu/quarto-menu.js"></script>
2871 2872
2872<script src="index_files/libs/revealjs/plugin/reveal-chalkboard/plugin.js"></script>
2872 2873
2873<script src="index_files/libs/revealjs/plugin/reveal-attribution/attribution.js"></script>
2873 2874
2874<script src="index_files/libs/revealjs/plugin/simplemenu/simplemenu.js"></script>
2874 2875
2875<script src="index_files/libs/revealjs/plugin/quarto-support/support.js"></script>
2875 2876 2877 2878
2878<script src="index_files/libs/revealjs/plugin/notes/notes.js"></script>
2878 2879
2879<script src="index_files/libs/revealjs/plugin/search/search.js"></script>
2879 2880
2880<script src="index_files/libs/revealjs/plugin/zoom/zoom.js"></script>
2880 2881
2881<script>window.define = window.backupDefine; window.backupDefine = undefined;</script>
2881 2882 2883
2883<script> 2884 2885 // Full list of configuration options available at: 2886 // https://revealjs.com/config/ 2887 Reveal.initialize({ 2888'controlsAuto': true, 2889'previewLinksAuto': true, 2890'pdfSeparateFragments': false, 2891'autoAnimateEasing': "ease", 2892'autoAnimateDuration': 1, 2893'autoAnimateUnmatched': true, 2894'jumpToSlide': true, 2895'menu': {"side":"left","useTextContentForMissingTitles":true,"markers":false,"loadIcons":false,"custom":[{"title":"Tools","icon":"<i class=\"fas fa-gear\"></i>","content":"<ul class=\"slide-menu-items\">\n<li class=\"slide-tool-item active\" data-item=\"0\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.fullscreen(event)\"><kbd>f</kbd> Fullscreen</a></li>\n<li class=\"slide-tool-item\" data-item=\"1\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.speakerMode(event)\"><kbd>s</kbd> Speaker View</a></li>\n<li class=\"slide-tool-item\" data-item=\"2\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.overview(event)\"><kbd>o</kbd> Slide Overview</a></li>\n<li class=\"slide-tool-item\" data-item=\"3\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.togglePdfExport(event)\"><kbd>e</kbd> PDF Export Mode</a></li>\n<li class=\"slide-tool-item\" data-item=\"4\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.toggleScrollView(event)\"><kbd>r</kbd> Scroll View Mode</a></li>\n<li class=\"slide-tool-item\" data-item=\"5\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.toggleChalkboard(event)\"><kbd>b</kbd> Toggle Chalkboard</a></li>\n<li class=\"slide-tool-item\" data-item=\"6\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.toggleNotesCanvas(event)\"><kbd>c</kbd> Toggle Notes Canvas</a></li>\n<li class=\"slide-tool-item\" data-item=\"7\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.downloadDrawings(event)\"><kbd>d</kbd> Download Drawings</a></li>\n<li class=\"slide-tool-item\" data-item=\"8\"><a href=\"#\" onclick=\"RevealMenuToolHandlers.keyboardHelp(event)\"><kbd>?</kbd> Keyboard Help</a></li>\n</ul>"}],"openButton":true,"numbers":true,"width":"wide"}, 2896'chalkboard': {"buttons":true}, 2897'simplemenu': {"menubarclass":"menubar","menuclass":"menu","activeclass":"active","activeelement":"li","flat":false,"barhtml":{"header":"","footer":""},"scale":0.67}, 2898'smaller': false, 2899 2900 // Display controls in the bottom right corner 2901 controls: false, 2902 2903 // Help the user learn the controls by providing hints, for example by 2904 // bouncing the down arrow when they first encounter a vertical slide 2905 controlsTutorial: false, 2906 2907 // Determines where controls appear, "edges" or "bottom-right" 2908 controlsLayout: 'edges', 2909 2910 // Visibility rule for backwards navigation arrows; "faded", "hidden" 2911 // or "visible" 2912 controlsBackArrows: 'faded', 2913 2914 // Display a presentation progress bar 2915 progress: true, 2916 2917 // Display the page number of the current slide 2918 slideNumber: false, 2919 2920 // 'all', 'print', or 'speaker' 2921 showSlideNumber: 'all', 2922 2923 // Add the current slide number to the URL hash so that reloading the 2924 // page/copying the URL will return you to the same slide 2925 hash: true, 2926 2927 // Start with 1 for the hash rather than 0 2928 hashOneBasedIndex: false, 2929 2930 // Flags if we should monitor the hash and change slides accordingly 2931 respondToHashChanges: true, 2932 2933 // Push each slide change to the browser history 2934 history: true, 2935 2936 // Enable keyboard shortcuts for navigation 2937 keyboard: true, 2938 2939 // Enable the slide overview mode 2940 overview: true, 2941 2942 // Disables the default reveal.js slide layout (scaling and centering) 2943 // so that you can use custom CSS layout 2944 disableLayout: false, 2945 2946 // Vertical centering of slides 2947 center: false, 2948 2949 // Enables touch navigation on devices with touch input 2950 touch: true, 2951 2952 // Loop the presentation 2953 loop: false, 2954 2955 // Change the presentation direction to be RTL 2956 rtl: false, 2957 2958 // see https://revealjs.com/vertical-slides/#navigation-mode 2959 navigationMode: 'linear', 2960 2961 // Randomizes the order of slides each time the presentation loads 2962 shuffle: false, 2963 2964 // Turns fragments on and off globally 2965 fragments: true, 2966 2967 // Flags whether to include the current fragment in the URL, 2968 // so that reloading brings you to the same fragment position 2969 fragmentInURL: false, 2970 2971 // Flags if the presentation is running in an embedded mode, 2972 // i.e. contained within a limited portion of the screen 2973 embedded: false, 2974 2975 // Flags if we should show a help overlay when the questionmark 2976 // key is pressed 2977 help: true, 2978 2979 // Flags if it should be possible to pause the presentation (blackout) 2980 pause: true, 2981 2982 // Flags if speaker notes should be visible to all viewers 2983 showNotes: false, 2984 2985 // Global override for autoplaying embedded media (null/true/false) 2986 autoPlayMedia: null, 2987 2988 // Global override for preloading lazy-loaded iframes (null/true/false) 2989 preloadIframes: null, 2990 2991 // Number of milliseconds between automatically proceeding to the
2992 // next slide, disabled when set to 0, this value can be overwritten 2993 // by using a data-autoslide attribute on your slides 2994 autoSlide: 0, 2995 2996 // Stop auto-sliding after user input 2997 autoSlideStoppable: true, 2998 2999 // Use this method for navigation when auto-sliding 3000 autoSlideMethod: null, 3001 3002 // Specify the average time in seconds that you think you will spend 3003 // presenting each slide. This is used to show a pacing timer in the 3004 // speaker view 3005 defaultTiming: null, 3006 3007 // Enable slide navigation via mouse wheel 3008 mouseWheel: false, 3009 3010 // The display mode that will be used to show slides 3011 display: 'block', 3012 3013 // Hide cursor if inactive 3014 hideInactiveCursor: true, 3015 3016 // Time before the cursor is hidden (in ms) 3017 hideCursorTime: 5000, 3018 3019 // Opens links in an iframe preview overlay 3020 previewLinks: false, 3021 3022 // Transition style (none/fade/slide/convex/concave/zoom) 3023 transition: 'none', 3024 3025 // Transition speed (default/fast/slow) 3026 transitionSpeed: 'default', 3027 3028 // Transition style for full page slide backgrounds 3029 // (none/fade/slide/convex/concave/zoom) 3030 backgroundTransition: 'none', 3031 3032 // Number of slides away from the current that are visible 3033 viewDistance: 3, 3034 3035 // Number of slides away from the current that are visible on mobile 3036 // devices. It is advisable to set this to a lower number than 3037 // viewDistance in order to save resources. 3038 mobileViewDistance: 2, 3039 3040 // The "normal" size of the presentation, aspect ratio will be preserved 3041 // when the presentation is scaled to fit different resolutions. Can be 3042 // specified using percentage units. 3043 width: 1050, 3044 3045 height: 700, 3046 3047 // Factor of the display size that should remain empty around the content 3048 margin: 0.1, 3049 3050 // reveal.js plugins 3051 plugins: [QuartoLineHighlight, PdfExport, RevealMenu, RevealChalkboard, RevealAttribution, Simplemenu, QuartoSupport, 3052 3053 RevealNotes, 3054 RevealSearch, 3055 RevealZoom 3056 ] 3057 }); 3058 </script>
3058 3059 3060
3060<script> 3061 // htmlwidgets need to know to resize themselves when slides are shown/hidden. 3062 // Fire the "slideenter" event (handled by htmlwidgets.js) when the current 3063 // slide changes (different for each slide format). 3064 (function () { 3065 // dispatch for htmlwidgets 3066 function fireSlideEnter() { 3067 const event = window.document.createEvent("Event"); 3068 event.initEvent("slideenter", true, true); 3069 window.document.dispatchEvent(event); 3070 } 3071 3072 function fireSlideChanged(previousSlide, currentSlide) { 3073 fireSlideEnter(); 3074 3075 // dispatch for shiny 3076 if (window.jQuery) { 3077 if (previousSlide) { 3078 window.jQuery(previousSlide).trigger("hidden"); 3079 } 3080 if (currentSlide) { 3081 window.jQuery(currentSlide).trigger("shown"); 3082 } 3083 } 3084 } 3085 3086 // hookup for slidy 3087 if (window.w3c_slidy) { 3088 window.w3c_slidy.add_observer(function (slide_num) { 3089 // slide_num starts at position 1 3090 fireSlideChanged(null, w3c_slidy.slides[slide_num - 1]); 3091 }); 3092 } 3093 3094 })(); 3095 </script>
3095 3096 3097
3097<script id="quarto-html-after-body" type="application/javascript"> 3098 window.document.addEventListener("DOMContentLoaded", function (event) { 3099 const tabsets = window.document.querySelectorAll(".panel-tabset-tabby") 3100 tabsets.forEach(function(tabset) { 3101 const tabby = new Tabby('#' + tabset.id); 3102 }); 3103 const isCodeAnnotation = (el) => { 3104 for (const clz of el.classList) { 3105 if (clz.startsWith('code-annotation-')) { 3106 return true; 3107 } 3108 } 3109 return false; 3110 } 3111 const onCopySuccess = function(e) { 3112 // button target 3113 const button = e.trigger; 3114 // don't keep focus 3115 button.blur(); 3116 // flash "checked" 3117 button.classList.add('code-copy-button-checked'); 3118 var currentTitle = button.getAttribute("title"); 3119 button.setAttribute("title", "Copied!"); 3120 let tooltip; 3121 if (window.bootstrap) { 3122 button.setAttribute("data-bs-toggle", "tooltip"); 3123 button.setAttribute("data-bs-placement", "left"); 3124 button.setAttribute("data-bs-title", "Copied!"); 3125 tooltip = new bootstrap.Tooltip(button, 3126 { trigger: "manual", 3127 customClass: "code-copy-button-tooltip", 3128 offset: [0, -8]}); 3129 tooltip.show(); 3130 } 3131 setTimeout(function() { 3132 if (tooltip) { 3133 tooltip.hide(); 3134 button.removeAttribute("data-bs-title"); 3135 button.removeAttribute("data-bs-toggle"); 3136 button.removeAttribute("data-bs-placement"); 3137 } 3138 button.setAttribute("title", currentTitle); 3139 button.classList.remove('code-copy-button-checked'); 3140 }, 1000); 3141 // clear code selection 3142 e.clearSelection(); 3143 } 3144 const getTextToCopy = function(trigger) { 3145 const codeEl = trigger.previousElementSibling.cloneNode(true); 3146 for (const childEl of codeEl.children) { 3147 if (isCodeAnnotation(childEl)) { 3148 childEl.remove(); 3149 } 3150 } 3151 return codeEl.innerText; 3152 } 3153 const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { 3154 text: getTextToCopy 3155 }); 3156 clipboard.on('success', onCopySuccess); 3157 if (window.document.getElementById('quarto-embedded-source-code-modal')) { 3158 const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', { 3159 text: getTextToCopy, 3160 container: window.document.getElementById('quarto-embedded-source-code-modal') 3161 }); 3162 clipboardModal.on('success', onCopySuccess); 3163 } 3164 var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//); 3165 var mailtoRegex = new RegExp(/^mailto:/); 3166 var filterRegex = new RegExp('/' + window.location.host + '/'); 3167 var isInternal = (href) => { 3168 return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href); 3169 } 3170 // Inspect non-navigation links and adorn them if external 3171 var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)'); 3172 for (var i=0; i<links.length; i++) { 3173 const link = links[i]; 3174 if (!isInternal(link.href)) { 3175 // undo the damage that might have been done by quarto-nav.js in the case of 3176 // links that we want to consider external 3177 if (link.dataset.originalHref !== undefined) { 3178 link.href = link.dataset.originalHref; 3179 } 3180 // default icon 3181 link.classList.add("external"); 3182 } 3183 } 3184 function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) { 3185 const config = { 3186 allowHTML: true, 3187 maxWidth: 500, 3188 delay: 100,
3189 arrow: false, 3190 appendTo: function(el) { 3191 return el.closest('section.slide') || el.parentElement; 3192 }, 3193 interactive: true, 3194 interactiveBorder: 10, 3195 theme: 'light-border', 3196 placement: 'bottom-start', 3197 }; 3198 if (contentFn) { 3199 config.content = contentFn; 3200 } 3201 if (onTriggerFn) { 3202 config.onTrigger = onTriggerFn; 3203 } 3204 if (onUntriggerFn) { 3205 config.onUntrigger = onUntriggerFn; 3206 } 3207 config['offset'] = [0,0]; 3208 config['maxWidth'] = 700; 3209 window.tippy(el, config); 3210 } 3211 const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]'); 3212 for (var i=0; i<noterefs.length; i++) { 3213 const ref = noterefs[i]; 3214 tippyHover(ref, function() { 3215 // use id or data attribute instead here 3216 let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href'); 3217 try { href = new URL(href).hash; } catch {} 3218 const id = href.replace(/^#\/?/, ""); 3219 const note = window.document.getElementById(id); 3220 if (note) { 3221 return note.innerHTML; 3222 } else { 3223 return ""; 3224 } 3225 }); 3226 } 3227 let selectedAnnoteEl; 3228 const selectorForAnnotation = ( cell, annotation) => { 3229 let cellAttr = 'data-code-cell="' + cell + '"'; 3230 let lineAttr = 'data-code-annotation="' + annotation + '"'; 3231 const selector = 'span[' + cellAttr + '][' + lineAttr + ']'; 3232 return selector; 3233 } 3234 const selectCodeLines = (annoteEl) => { 3235 const doc = window.document; 3236 const targetCell = annoteEl.getAttribute("data-target-cell"); 3237 const targetAnnotation = annoteEl.getAttribute("data-target-annotation"); 3238 const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation)); 3239 const lines = annoteSpan.getAttribute("data-code-lines").split(","); 3240 const lineIds = lines.map((line) => { 3241 return targetCell + "-" + line; 3242 }) 3243 let top = null; 3244 let height = null; 3245 let parent = null; 3246 if (lineIds.length > 0) { 3247 //compute the position of the single el (top and bottom and make a div) 3248 const el = window.document.getElementById(lineIds[0]); 3249 top = el.offsetTop; 3250 height = el.offsetHeight; 3251 parent = el.parentElement.parentElement; 3252 if (lineIds.length > 1) { 3253 const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]); 3254 const bottom = lastEl.offsetTop + lastEl.offsetHeight; 3255 height = bottom - top; 3256 } 3257 if (top !== null && height !== null && parent !== null) { 3258 // cook up a div (if necessary) and position it 3259 let div = window.document.getElementById("code-annotation-line-highlight"); 3260 if (div === null) { 3261 div = window.document.createElement("div"); 3262 div.setAttribute("id", "code-annotation-line-highlight"); 3263 div.style.position = 'absolute'; 3264 parent.appendChild(div); 3265 } 3266 div.style.top = top - 2 + "px"; 3267 div.style.height = height + 4 + "px"; 3268 div.style.left = 0; 3269 let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter"); 3270 if (gutterDiv === null) { 3271 gutterDiv = window.document.createElement("div"); 3272 gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter"); 3273 gutterDiv.style.position = 'absolute'; 3274 const codeCell = window.document.getElementById(targetCell); 3275 const gutter = codeCell.querySelector('.code-annotation-gutter'); 3276 gutter.appendChild(gutterDiv); 3277 } 3278 gutterDiv.style.top = top - 2 + "px"; 3279 gutterDiv.style.height = height + 4 + "px"; 3280 } 3281 selectedAnnoteEl = annoteEl; 3282 } 3283 }; 3284 const unselectCodeLines = () => { 3285 const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"]; 3286 elementsIds.forEach((elId) => { 3287 const div = window.document.getElementById(elId); 3288 if (div) { 3289 div.remove(); 3290 } 3291 }); 3292 selectedAnnoteEl = undefined; 3293 }; 3294 // Handle positioning of the toggle 3295 window.addEventListener( 3296 "resize", 3297 throttle(() => { 3298 elRect = undefined; 3299 if (selectedAnnoteEl) { 3300 selectCodeLines(selectedAnnoteEl); 3301 } 3302 }, 10) 3303 ); 3304 function throttle(fn, ms) { 3305 let throttle = false;
3306 let timer; 3307 return (...args) => { 3308 if(!throttle) { // first call gets through 3309 fn.apply(this, args); 3310 throttle = true; 3311 } else { // all the others get throttled 3312 if(timer) clearTimeout(timer); // cancel #2 3313 timer = setTimeout(() => { 3314 fn.apply(this, args); 3315 timer = throttle = false; 3316 }, ms); 3317 } 3318 }; 3319 } 3320 const annoteTargets = window.document.querySelectorAll('.code-annotation-anchor'); 3321 for (let i=0; i<annoteTargets.length; i++) { 3322 const annoteTarget = annoteTargets[i]; 3323 const targetCell = annoteTarget.getAttribute("data-target-cell"); 3324 const targetAnnotation = annoteTarget.getAttribute("data-target-annotation"); 3325 const contentFn = () => { 3326 const content = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation)); 3327 if (content) { 3328 const tipContent = content.cloneNode(true); 3329 tipContent.classList.add("code-annotation-tip-content"); 3330 return tipContent.outerHTML; 3331 } 3332 } 3333 const config = { 3334 allowHTML: true, 3335 content: contentFn, 3336 onShow: (instance) => { 3337 selectCodeLines(instance.reference); 3338 instance.reference.classList.add('code-annotation-active'); 3339 window.tippy.hideAll(); 3340 }, 3341 onHide: (instance) => { 3342 unselectCodeLines(); 3343 instance.reference.classList.remove('code-annotation-active'); 3344 }, 3345 maxWidth: 300, 3346 delay: [50, 0], 3347 duration: [200, 0], 3348 offset: [5, 10], 3349 arrow: true, 3350 trigger: 'click', 3351 appendTo: function(el) { 3352 return el.parentElement.parentElement.parentElement; 3353 }, 3354 interactive: true, 3355 interactiveBorder: 10, 3356 theme: 'light-border', 3357 placement: 'right', 3358 positionFixed: true, 3359 popperOptions: { 3360 modifiers: [ 3361 { 3362 name: 'flip', 3363 options: { 3364 flipVariations: false, // true by default 3365 allowedAutoPlacements: ['right'], 3366 fallbackPlacements: ['right', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left'], 3367 }, 3368 }, 3369 { 3370 name: 'preventOverflow', 3371 options: { 3372 mainAxis: false, 3373 altAxis: false 3374 } 3375 } 3376 ] 3377 } 3378 }; 3379 window.tippy(annoteTarget, config); 3380 } 3381 const findCites = (el) => { 3382 const parentEl = el.parentElement; 3383 if (parentEl) { 3384 const cites = parentEl.dataset.cites; 3385 if (cites) { 3386 return { 3387 el, 3388 cites: cites.split(' ') 3389 }; 3390 } else { 3391 return findCites(el.parentElement) 3392 } 3393 } else { 3394 return undefined; 3395 } 3396 }; 3397 var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); 3398 for (var i=0; i<bibliorefs.length; i++) { 3399 const ref = bibliorefs[i]; 3400 const citeInfo = findCites(ref); 3401 if (citeInfo) { 3402 tippyHover(citeInfo.el, function() { 3403 var popup = window.document.createElement('div'); 3404 citeInfo.cites.forEach(function(cite) { 3405 var citeDiv = window.document.createElement('div'); 3406 citeDiv.classList.add('hanging-indent'); 3407 citeDiv.classList.add('csl-entry'); 3408 var biblioDiv = window.document.getElementById('ref-' + cite); 3409 if (biblioDiv) { 3410 citeDiv.innerHTML = biblioDiv.innerHTML; 3411 } 3412 popup.appendChild(citeDiv); 3413 }); 3414 return popup.innerHTML; 3415 }); 3416 } 3417 } 3418 }); 3419 </script>
3419 3420
3420<script type="module"> 3421 // Handle cell initialization initialization 3422 qwebrCellDetails.map( 3423 (entry) => { 3424 // Handle the creation of the element 3425 qwebrCreateHTMLElement(entry); 3426 // In the event of interactive, initialize the monaco editor 3427 if (entry.options.context == EvalTypes.Interactive) { 3428 qwebrCreateMonacoEditorInstance(entry); 3429 } 3430 } 3431 ); 3432 3433 // Identify non-interactive cells (in order) 3434 const filteredEntries = qwebrCellDetails.filter(entry => { 3435 const contextOption = entry.options && entry.options.context; 3436 return ['output', 'setup'].includes(contextOption) || (contextOption == "interactive" && entry.options && entry.options.autorun === 'true'); 3437 }); 3438 3439 // Condition non-interactive cells to only be run after webR finishes its initialization. 3440 qwebrInstance.then( 3441 async () => { 3442 const nHiddenCells = filteredEntries.length; 3443 var currentHiddenCell = 0; 3444 3445 3446 // Modify button state 3447 qwebrSetInteractiveButtonState(`ð¡ Running hidden code cells ...`, false); 3448 3449 // Begin processing non-interactive sections 3450 // Due to the iteration policy, we must use a for() loop. 3451 // Otherwise, we would need to switch to using reduce with an empty 3452 // starting promise 3453 for (const entry of filteredEntries) { 3454 3455 // Determine cell being examined 3456 currentHiddenCell = currentHiddenCell + 1; 3457 const formattedMessage = `Evaluating hidden cell ${currentHiddenCell} out of ${nHiddenCells}`; 3458 3459 // Update the document status header 3460 if (qwebrShowStartupMessage) { 3461 qwebrUpdateStatusHeader(formattedMessage); 3462 } 3463 3464 // Display the update in non-active areas 3465 qwebrUpdateStatusMessage(formattedMessage); 3466 3467 // Extract details on the active cell 3468 const evalType = entry.options.context; 3469 const cellCode = entry.code; 3470 const qwebrCounter = entry.id; 3471 3472 if (['output', 'setup'].includes(evalType)) { 3473 // Disable further global status updates 3474 const activeContainer = document.getElementById(`qwebr-non-interactive-loading-container-${qwebrCounter}`); 3475 activeContainer.classList.remove('qwebr-cell-needs-evaluation'); 3476 activeContainer.classList.add('qwebr-cell-evaluated'); 3477 3478 // Update status on the code cell 3479 const activeStatus = document.getElementById(`qwebr-status-text-${qwebrCounter}`); 3480 activeStatus.innerText = " Evaluating hidden code cell..."; 3481 activeStatus.classList.remove('qwebr-cell-needs-evaluation'); 3482 activeStatus.classList.add('qwebr-cell-evaluated'); 3483 } 3484 3485 switch (evalType) { 3486 case 'interactive': 3487 // TODO: Make this more standardized. 3488 // At the moment, we're overriding the interactive status update by pretending its 3489 // output-like. 3490 const tempOptions = entry.options; 3491 tempOptions["context"] = "output" 3492 // Run the code in a non-interactive state that is geared to displaying output 3493 await qwebrExecuteCode(`${cellCode}`, qwebrCounter, tempOptions); 3494 break; 3495 case 'output': 3496 // Run the code in a non-interactive state that is geared to displaying output 3497 await qwebrExecuteCode(`${cellCode}`, qwebrCounter, entry.options); 3498 break; 3499 case 'setup': 3500 const activeDiv = document.getElementById(`qwebr-noninteractive-setup-area-${qwebrCounter}`); 3501 3502 // Store code in history 3503 qwebrLogCodeToHistory(cellCode, entry.options); 3504 3505 // Run the code in a non-interactive state with all output thrown away 3506 await mainWebR.evalRVoid(`${cellCode}`); 3507 break; 3508 default: 3509 break; 3510 } 3511 3512 if (['output', 'setup'].includes(evalType)) { 3513 // Disable further global status updates 3514 const activeContainer = document.getElementById(`qwebr-non-interactive-loading-container-${qwebrCounter}`); 3515 // Disable visibility 3516 activeContainer.style.visibility = 'hidden'; 3517 activeContainer.style.display = 'none'; 3518 } 3519 } 3520 } 3521 ).then( 3522 () => { 3523 // Release document status as ready 3524 3525 if (qwebrShowStartupMessage) { 3526 qwebrStartupMessage.innerText = "ð¢ Ready!" 3527 } 3528 3529 qwebrSetInteractiveButtonState( 3530 `<i class="fa-solid fa-play qwebr-icon-run-code"></i> <span>
3530Run Code</span>`, 3531 true 3532 ); 3533 } 3534 ); 3535 </script>
3535 3536
3536<script>var lightboxQuarto = GLightbox({"closeEffect":"zoom","descPosition":"bottom","loop":false,"openEffect":"zoom","selector":".lightbox"}); 3537 (function() { 3538 let previousOnload = window.onload; 3539 window.onload = () => { 3540 if (previousOnload) { 3541 previousOnload(); 3542 } 3543 lightboxQuarto.on('slide_before_load', (data) => { 3544 const { slideIndex, slideNode, slideConfig, player, trigger } = data; 3545 const href = trigger.getAttribute('href'); 3546 if (href !== null) { 3547 const imgEl = window.document.querySelector(`a[href="${href}"] img`); 3548 if (imgEl !== null) { 3549 const srcAttr = imgEl.getAttribute("src"); 3550 if (srcAttr && srcAttr.startsWith("data:")) { 3551 slideConfig.href = srcAttr; 3552 } 3553 } 3554 } 3555 }); 3556 3557 lightboxQuarto.on('slide_after_load', (data) => { 3558 const { slideIndex, slideNode, slideConfig, player, trigger } = data; 3559 if (window.Quarto?.typesetMath) { 3560 window.Quarto.typesetMath(slideNode); 3561 } 3562 }); 3563 3564 }; 3565 3566 })(); 3567 </script>
3567 3568 3569 3570</body></html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.