Skip to content

Commit

Permalink
redeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed May 18, 2021
1 parent a3346bf commit 5a85eb6
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 100 deletions.
2 changes: 2 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ book:
objects, navigate R's environment system, write your own functions, and
use all of R's programming tools. Throughout the book, you'll use your
newfound skills to solve practical data science problems.
cover-image: images/cover.png
site-url: https://rstudio-education.github.io/hopr/
repo-url: https://github.com/jjallaire/hopr/
repo-branch: master
Expand Down Expand Up @@ -46,5 +47,6 @@ book:
format:
html:
theme: cosmo
cover-image: cover.png
code-link: true

6 changes: 4 additions & 2 deletions docs/a1-starting.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
.quarto-layout-cell-subref figcaption {
font-style: italic;
}
.quarto-figure {
position: relative;
}
.quarto-figure > figure {
width: 100%;
}
Expand Down Expand Up @@ -447,7 +450,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix A — Install
</div>
</div>
<p>When you open RStudio, a window appears with three panes in it, as in <a href="#fig:layout">fig.&nbsp;<span>A.1</span></a>. The largest pane is a console window. This is where you’ll run your R code and see results. The console window is exactly what you’d see if you ran R from a UNIX console or the Windows or Mac GUIs. Everything else you see is unique to RStudio. Hidden in the other panes are a text editor, a graphics window, a debugger, a file manager, and much more. You’ll learn about these panes as they become useful throughout the course of this book.</p>
<div id="fig:layout" class="quarto-figure quarto-figure-center">
<div id="fig:layout" class="quarto-figure quarto-figure-center anchored">
<figure class="figure"><p><img src="images/hopr_aa01.png" class="img-fluid figure-img"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Figure A.1: The RStudio IDE for R.</figcaption><p></p>
</figure>
Expand Down Expand Up @@ -486,5 +489,4 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix A — Install
</div> <!-- /container fluid -->



</body></html>
1 change: 0 additions & 1 deletion docs/a2-packages.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,4 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix B — R Packa
</div> <!-- /container fluid -->



</body></html>
1 change: 0 additions & 1 deletion docs/a3-updating.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,4 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix C — Updatin
</div> <!-- /container fluid -->



</body></html>
9 changes: 4 additions & 5 deletions docs/a4-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix D — Loading
</section></section><section class="level3" data-number="D.3.2"><h3 data-number="D.3.2" class="anchored" id="the-read-family">
<span class="header-section-number">D.3.2</span> The read Family</h3>
<p>R also comes with some prepackaged short cuts for <code>read.table</code>, shown in <a href="#tbl:shortcuts">tbl.&nbsp;<span>D.1</span></a>.</p>
<div id="tbl:shortcuts">
<div id="tbl:shortcuts" class="anchored">
<table class="table">
<caption>Table D.1: R’s read functions. You can overwrite any of the default arguments as necessary. </caption>
<colgroup>
Expand Down Expand Up @@ -508,7 +508,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix D — Loading
</section><section class="level3" data-number="D.3.5"><h3 data-number="D.3.5" class="anchored" id="saving-plain-text-files">
<span class="header-section-number">D.3.5</span> Saving Plain-Text Files</h3>
<p>Once your data is in R, you can save it to any file format that R supports. If you’d like to save it as a plain-text file, you can use the +write+ family of functions. The three basic write functions appear in <a href="#tbl:write">tbl.&nbsp;<span>D.2</span></a>. Use <code>write.csv</code> to save your data as a <em>.csv</em> file and <code>write.table</code> to save your data as a tab delimited document or a document with more exotic separators.</p>
<div id="tbl:write">
<div id="tbl:write" class="anchored">
<table class="table">
<caption>Table D.2: R saves data sets to plain-text files with the write family of functions </caption>
<colgroup>
Expand Down Expand Up @@ -554,7 +554,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix D — Loading
<p>To compress a plain-text file, surround the file name or file path with the function <code>bzfile</code>, <code>gzfile</code>, or <code>xzfile</code>. For example:</p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r"><code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/utils/write.table.html">write.csv</a></span><span class="op">(</span><span class="va">poker</span>, file <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/connections.html">bzfile</a></span><span class="op">(</span><span class="st">"data/poker.csv.bz2"</span><span class="op">)</span>, row.names <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Each of these functions will compress the output with a different type of compression format, shown in <a href="#tbl:compression">tbl.&nbsp;<span>D.3</span></a>.</p>
<div id="tbl:compression">
<div id="tbl:compression" class="anchored">
<table class="table">
<caption>Table D.3: R comes with three helper functions for compressing files </caption>
<thead><tr class="header">
Expand Down Expand Up @@ -660,7 +660,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix D — Loading
<span class="header-section-number">D.6</span> Loading Files from Other Programs</h2>
<p>You should follow the same advice I gave you for Excel files whenever you wish to work with file formats native to other programs: open the file in the original program and export the data as a plain-text file, usually a CSV. This will ensure the most faithful transcription of the data in the file, and it will usually give you the most options for customizing how the data is transcribed.</p>
<p>Sometimes, however, you may acquire a file but not the program it came from. As a result, you won’t be able to open the file in its native program and export it as a text file. In this case, you can use one of the functions in <a href="#tbl:others">tbl.&nbsp;<span>D.4</span></a> to open the file. These functions mostly come in R’s <code>foreign</code> package. Each attempts to read in a different file format with as few hiccups as possible.</p>
<div id="tbl:others">
<div id="tbl:others" class="anchored">
<table class="table">
<caption>Table D.4: A number of functions will attempt to read the file types of other data-analysis programs </caption>
<thead><tr class="header">
Expand Down Expand Up @@ -735,5 +735,4 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix D — Loading
</div> <!-- /container fluid -->



</body></html>
14 changes: 8 additions & 6 deletions docs/a5-debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
.quarto-layout-cell-subref figcaption {
font-style: italic;
}
.quarto-figure {
position: relative;
}
.quarto-figure > figure {
width: 100%;
}
Expand Down Expand Up @@ -418,14 +421,14 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix E — Debuggi
<span class="co">## ...</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Notice that there are 5,000 lines of output in this <code>traceback</code>. If you are using RStudio, you will not get to see the traceback of an infinite recursion error (I used the Mac GUI to get this output). RStudio represses the traceback for infinite recursion errors to prevent the large call stacks from pushing your console history out of R’s memory buffer. With RStudio, you will have to recognize the infinite recursion error by its error message. However, you can still see the imposing <code>traceback</code> by running things in a UNIX shell or the Windows or Mac GUIs.</p>
<p>RStudio makes it very easy to use <code>traceback</code>. You do not even need to type in the function name. Whenever an error occurs, RStudio will display it in a gray box with two options. The first is Show Traceback, shown in <a href="#fig:show-traceback">fig.&nbsp;<span>E.1</span></a>.</p>
<div id="fig:show-traceback" class="quarto-figure quarto-figure-center">
<div id="fig:show-traceback" class="quarto-figure quarto-figure-center anchored">
<figure class="figure"><p><img src="images/hopr_ae01.png" class="img-fluid figure-img" style="width:80.0%"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Figure E.1: RStudio’s Show Traceback option.</figcaption><p></p>
</figure>
</div>
<p>If you click Show Traceback, RStudio will expand the gray box and display the <code>traceback</code> call stack, as in <a href="#fig:hide-traceback">fig.&nbsp;<span>E.2</span></a>. The Show Traceback option will persist beside an error message in your console, even as you write new commands. This means that you can go back and look at the call stacks for all errors—not just the most recent error.</p>
<p>Imagine that you’ve used <code>traceback</code> to pinpoint a function that you think might cause a bug. Now what should you do? You should try to figure out what the function did to cause an error while it ran (if it did anything). You can examine how the function runs with <code>browser</code>.</p>
<div id="fig:hide-traceback" class="quarto-figure quarto-figure-center">
<div id="fig:hide-traceback" class="quarto-figure quarto-figure-center anchored">
<figure class="figure"><p><img src="images/hopr_ae02.png" class="img-fluid figure-img"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Figure E.2: RStudio’s Traceback display.</figcaption><p></p>
</figure>
Expand Down Expand Up @@ -471,7 +474,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix E — Debuggi
<p>When you run <code>play</code>, <code>play</code> will call <code>get_symbols</code> and then <code>score</code>. As R works through <code>score</code>, it will come across the call to <code>browser</code> and run it. When R runs this call, several things will happen, as in <a href="#fig:browser">fig.&nbsp;<span>E.3</span></a>. First, R will stop running <code>score</code>. Second, the command prompt will change to <code>browser[1]&gt;</code> and R will give me back control; I can now type new commands in at the new command prompt. Third, three buttons will appear above the console pane: Next, Continue, and Stop. Fourth, RStudio will display the source code for <code>score</code> in the scripts pane, and it will highlight the line that contains <code><a href="https://rdrr.io/r/base/browser.html">browser()</a></code>. Fifth, the environments tab will change. Instead of revealing the objects that are saved in the global environment, it will reveal the objects that are saved in the runtime environment of <code>score</code> (see [Environments] for an explanation of R’s environment system). Sixth, RStudio will open a new Traceback pane, which shows the call stack RStudio took to get to <code>browser</code>. The most recent function, <code>score</code>, will be highlighted.</p>
<p>I’m now in a new R mode, called <em>browser mode</em>. Browser mode is designed to help you uncover bugs, and the new display in RStudio is designed to help you navigate this mode.</p>
<p>Any command that you run in browser mode will be evaluated in the context of the runtime environment of the function that called <code>browser</code>. This will be the function that is highlighted in the new Traceback pane. Here, that function is <code>score</code>. So while we are in browser mode, the active environment will be <code>score</code>’s runtime environment. This lets you do two things.</p>
<div id="fig:browser" class="quarto-figure quarto-figure-center">
<div id="fig:browser" class="quarto-figure quarto-figure-center anchored">
<figure class="figure"><p><img src="images/hopr_ae03.png" class="img-fluid figure-img"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Figure E.3: RStudio updates its display whenever you enter browser mode to help you navigate the mode.</figcaption><p></p>
</figure>
Expand All @@ -486,7 +489,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix E — Debuggi
<p>The first button, Next, will run the next line of code in <code>score</code>. The highlighted line in the scripts pane will advance by one line to show you your new location in the <code>score</code> function. If the next line begins a code chunk, like a <code>for</code> loop or an <code>if</code> tree, R will run the whole chunk and will highlight the whole chunk in the script window.</p>
<p>The second button, Continue, will run all of the remaining lines of <code>score</code> and then exit the browser mode.</p>
<p>The third button, Stop, will exit browser mode without running any more lines of <code>score</code>.</p>
<div id="fig:browser-buttons" class="quarto-figure quarto-figure-center">
<div id="fig:browser-buttons" class="quarto-figure quarto-figure-center anchored">
<figure class="figure"><p><img src="images/hopr_ae04.png" class="img-fluid figure-img" style="width:80.0%"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Figure E.4: You can navigate browser mode with the three buttons at the top of the console pane.</figcaption><p></p>
</figure>
Expand All @@ -498,7 +501,7 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix E — Debuggi
<span class="header-section-number">E.3</span> Break Points</h2>
<p>RStudio’s break points provide a graphical way to add a <code>browser</code> statement to a function. To use them, open the script where you’ve defined a function. Then click to the left of the line number of the line of code in the function body where you’d like to add the browser statement. A hollow red dot will appear to show you where the break point will occur. Then run the script by clicking the Source button at the top of the Scripts pane. The hollow dot will turn into a solid red dot to show that the function has a break point (see <a href="#fig:break-point">fig.&nbsp;<span>E.5</span></a>).</p>
<p>R will treat the break point like a <code>browser</code> statement, going into browser mode when it encounters it. You can remove a break point by clicking on the red dot. The dot will disappear, and the break point will be removed.</p>
<div id="fig:break-point" class="quarto-figure quarto-figure-center">
<div id="fig:break-point" class="quarto-figure quarto-figure-center anchored">
<figure class="figure"><p><img src="images/hopr_ae05.png" class="img-fluid figure-img"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Figure E.5: Break points provide the graphical equivalent of a browser statement.</figcaption><p></p>
</figure>
Expand Down Expand Up @@ -577,5 +580,4 @@ <h1 class="quarto-secondary-nav-title mb-0 fs-3 d-inline">Appendix E — Debuggi
</div> <!-- /container fluid -->



</body></html>
Loading

0 comments on commit 5a85eb6

Please sign in to comment.