Skip to content

Commit b359cf7

Browse files
author
Susan Vanderplas
committed
Fixing more yaml
1 parent f4b880e commit b359cf7

File tree

10 files changed

+101
-100
lines changed

10 files changed

+101
-100
lines changed

part-gen-prog/06-debugging.qmd

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Redesigning your code to be more modular and more organized is also a good idea.
137137
In programming, as in life, big, general problems are very hard to solve effectively.
138138
Instead, the goal is to break a problem down into smaller pieces that may actually be solvable.
139139

140-
::: demo
140+
:::: demo
141141
### Demo: Exhaustion
142142

143143
This example inspired by @grimesThis500YearOldPiece2019.
@@ -201,7 +201,7 @@ In programming, of course, this list would perhaps be a bit more sequential, but
201201
- [2] Revise your to-do list and try a different tactic if what you were trying didn't work.
202202

203203
:::
204-
:::
204+
::::
205205

206206

207207
## Minimal Working (or Reproducible) Examples
@@ -239,7 +239,7 @@ Describe what you see and what you'd hope to see if the code were working.
239239
- [reprex magic - Vignette adapted from a blog post by Nick Tierney](https://reprex.tidyverse.org/articles/articles/magic-reprex.html)
240240
:::
241241

242-
::: demo
242+
:::: demo
243243
### Demo: Minimum Working Examples in Practice
244244

245245
::: panel-tabset
@@ -351,7 +351,7 @@ I didn't know enough python or enough about GitHub Actions to diagnose the probl
351351

352352
:::
353353

354-
:::
354+
::::
355355

356356
::: example
357357
### Example: Debugging Exercises
@@ -375,7 +375,7 @@ When the code is executed, you get a window into what the variables look like du
375375

376376
This is called **print debugging** and it is an incredibly useful tool.
377377

378-
::: demo
378+
:::: demo
379379
#### Demo: Nested Functions
380380

381381
::: panel-tabset
@@ -480,11 +480,11 @@ aa(5)
480480
```
481481
:::
482482

483-
:::
483+
::::
484484

485485
For more complex data structures, it can be useful to add `str()`, `head()`, or `summary()` functions.
486486

487-
::: demo
487+
:::: demo
488488
#### Real world demo: Web Scraping
489489

490490
In fall 2020, I wrote a webscraper to get election polling data from the RealClearPolitics site as part of the [`electionViz` package](https://www.github.com/heike/electionViz).
@@ -571,9 +571,9 @@ By printing out all of the tags that contain `node`, I could see the order -- in
571571
I asked the function to return the location of the first table node, so the index (2nd value printed out) should match table in the character vector that was printed out first.
572572
I could then see that the HTML node that is returned is in fact the table node.
573573

574-
:::
574+
::::
575575

576-
::: example
576+
:::: example
577577
#### Example: Hurricanes in R
578578

579579
Not all bugs result in error messages, unfortunately, which makes higher-level techniques like `traceback()` less useful.
@@ -791,7 +791,7 @@ for (i in 1:5) {
791791
```
792792
:::
793793

794-
:::
794+
::::
795795

796796
Once you've found your problem, go back and delete or comment out your print statements, as they're no longer necessary.
797797
If you think you may need them again, comment them out, otherwise, just delete them so that your code is neat, clean, and concise.
@@ -802,7 +802,7 @@ If you think you may need them again, comment them out, otherwise, just delete t
802802
`traceback()` can help you narrow down where an error occurs by taking you through the series of function calls that led up to the error.
803803
This may help you identify which function is actually causing the problem, which is especially useful when you have nested functions or are using package functions that depend on other packages.
804804

805-
::: demo
805+
:::: demo
806806
#### Demo: Using traceback
807807

808808
::: panel-tabset
@@ -875,7 +875,7 @@ Python's [traceback](https://docs.python.org/3/library/traceback.html) informati
875875

876876
:::
877877

878-
:::
878+
::::
879879

880880
### Interactive Debugging
881881

@@ -911,7 +911,9 @@ This ensures that ipdb is launched when an error is reached.
911911
:::
912912

913913
:::: example
914+
914915
#### Example: Interactive Debugging with XKCD {-}
916+
915917
::: panel-tabset
916918

917919
##### Problem {-}
@@ -988,7 +990,6 @@ get_xkcd() %>%
988990
as.raster() %>%
989991
plot()
990992
```
991-
:::
992993

993994

994995
##### Python {-}
@@ -1116,9 +1117,9 @@ plt.show()
11161117

11171118
:::
11181119

1119-
:::
1120+
::::
11201121

1121-
::: example
1122+
:::: example
11221123
#### Example: More Interactive Debugging with XKCD
11231124

11241125
::: panel-tabset
@@ -1246,7 +1247,7 @@ res = get_xkcd('abcd')
12461247

12471248
:::
12481249

1249-
:::
1250+
::::
12501251

12511252
### R `debug()`
12521253

@@ -1259,7 +1260,7 @@ So, if you can't change the code in the function causing the error, `debug()` is
12591260
Otherwise, using `browser()` is generally easier.
12601261
Essentially, `debug()` places a `browser()` statement at the first line of a function, but without having to actually alter the function's source code.
12611262

1262-
::: demo
1263+
:::: demo
12631264
#### Demo: `debug()` in R
12641265

12651266
```{r}
@@ -1301,12 +1302,12 @@ We probably could have gotten there from reading the error message carefully, bu
13011302

13021303
But, until I run `undebug(lm)`, every call to `lm` will take me into the debug window.
13031304

1304-
:::
1305+
::::
13051306

13061307
`undebug(f)` will remove the debug flag on the function `f`. `debugonce(f)` will only debug f the first time it is run.
13071308

13081309

1309-
::: example
1310+
:::: example
13101311
#### Example: `debug` in R
13111312

13121313
::: panel-tabset
@@ -1354,6 +1355,6 @@ larger <- function(x, y) {
13541355

13551356
:::
13561357

1357-
:::
1358+
::::
13581359

13591360
## References {#sec-debugging-refs}

part-wrangling/01-data-input.qmd

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ In base R (no extra packages), you can read fixed-width files in using `read.fwf
7979

8080
```{r}
8181
#| label: read-fwf-colbreaks
82-
#| error: !expr T
83-
#| eval: !expr '-1'
84-
#| echo: !expr '-2'
82+
#| error: true
83+
#| eval: -1
84+
#| echo: -2
8585
url <- "https://www.mesonet.org/index.php/dataMdfMts/dataController/getFile/202206070000/mdf/TEXT/"
8686
url <- "../data/mesodata.txt"
8787
data <- read.fwf(url,
@@ -143,7 +143,7 @@ You can also write fixed-width files if you *really* want to:
143143

144144
```{r}
145145
#| label: gdata-demo
146-
#| message: !expr F
146+
#| message: false
147147
if (!"gdata" %in% installed.packages()) install.packages("gdata")
148148
library(gdata)
149149
write.fwf(mtcars, file = tempfile())
@@ -155,7 +155,7 @@ The `readr` package creates data-frame like objects called tibbles (a souped-up
155155

156156
```{r}
157157
#| label: readr-demo
158-
#| message: !expr F
158+
#| message: false
159159
library(readr) # Better data importing in R
160160
161161
read_table(url, skip = 2) # Gosh, that was much easier!
@@ -189,7 +189,7 @@ Delimited text files are files where fields are separated by a specific characte
189189

190190
```{r}
191191
#| label: delimited-text-files-r
192-
#| collapse: !expr F
192+
#| collapse: false
193193
url <- "https://raw.githubusercontent.com/srvanderplas/datasets/main/clean/pokemon_gen_1-9.csv"
194194
195195
pokemon_info <- read.csv(url, header = T, stringsAsFactors = F)
@@ -204,7 +204,7 @@ The most common delimited text format is CSV: comma-separated value.
204204

205205
```{r}
206206
#| label: delimited-text-files-r3
207-
#| collapse: !expr F
207+
#| collapse: false
208208
library(readr)
209209
url <- "https://raw.githubusercontent.com/srvanderplas/datasets/main/clean/pokemon_gen_1-9.csv"
210210
pokemon_info <- read_csv(url)
@@ -218,7 +218,7 @@ There is a family of `read_xxx` functions in `pandas` including functions to rea
218218

219219
```{python}
220220
#| label: delimited-text-files-py
221-
#| collapse: !expr F
221+
#| collapse: false
222222
import pandas as pd
223223
224224
url <- "https://raw.githubusercontent.com/srvanderplas/datasets/main/clean/pokemon_gen_1-9.csv"
@@ -317,8 +317,8 @@ Because these data sets are comparatively large, they are available as compresse
317317

318318
```{r}
319319
#| label: rebrickable-lego-data-once
320-
#| eval: !expr T
321-
#| include: !expr F
320+
#| eval: true
321+
#| include: false
322322
# Download the data if it doesn't exist, as it's used later
323323
library(readr)
324324
if (!file.exists("../data/lego_sets.csv")) {
@@ -337,7 +337,7 @@ The `readr` package and `pandas` can handle .csv.gz files with no problems. Try
337337

338338
```{r}
339339
#| label: rebrickable-lego-data
340-
#| eval: !expr T
340+
#| eval: true
341341
library(readr)
342342
legosets <- read_csv("https://cdn.rebrickable.com/media/downloads/sets.csv.gz")
343343
write_csv(legosets, "../data/lego_sets.csv")
@@ -347,7 +347,7 @@ write_csv(legosets, "../data/lego_sets.csv")
347347
#### Python Solution {-}
348348
```{python}
349349
#| label: rebrickable-lego-data-py
350-
#| eval: !expr F
350+
#| eval: false
351351
import pandas as pd
352352
353353
legosets = pd.read_csv("https://cdn.rebrickable.com/media/downloads/sets.csv.gz")
@@ -374,7 +374,7 @@ It is usually helpful to open the spreadsheet up in a graphical program first to
374374

375375
```{r}
376376
#| label: spreadsheet-readin
377-
#| warning: !expr F
377+
#| warning: false
378378
if (!"readxl" %in% installed.packages()) install.packages("readxl")
379379
library(readxl)
380380
@@ -468,7 +468,7 @@ One simple hack-ish way to read google sheets in Python (so long as the sheet is
468468

469469
```{python}
470470
#| label: google-sheets-py2
471-
#| eval: !expr T
471+
#| eval: true
472472
import pandas as pd
473473
474474
sheet_id = "1wZhPLMCHKJvwOkP4juclhjFgqIY8fQFMemwKL2c64vk"
@@ -486,7 +486,7 @@ This method is described in @schaferReadDataGoogle2020 for Python, but I have ad
486486

487487
```{R}
488488
#| label: google-sheets-r2
489-
#| eval: !expr T
489+
#| eval: true
490490
library(readr)
491491
sheet_id = "1wZhPLMCHKJvwOkP4juclhjFgqIY8fQFMemwKL2c64vk"
492492
sheet_name = "Items"
@@ -506,7 +506,7 @@ Copy this code and run it on your computer to read in a sheet from google drive
506506

507507
```{r}
508508
#| label: google-sheets-r
509-
#| eval: !expr F
509+
#| eval: false
510510
library(googlesheets4)
511511
gs4_auth(scopes = "https://www.googleapis.com/auth/drive.readonly") # Read-only permissions
512512
data_is_plural <- read_sheet("https://docs.google.com/spreadsheets/d/1wZhPLMCHKJvwOkP4juclhjFgqIY8fQFMemwKL2c64vk/edit#gid=0")
@@ -521,7 +521,7 @@ Then, you will need to obtain a client token JSON file following [these instruct
521521

522522
```{python}
523523
#| label: google-sheets-py
524-
#| eval: !expr F
524+
#| eval: false
525525
import gspread as gs
526526
import pandas as pd
527527
```

part-wrangling/02-basic-data-vis.qmd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This section is intended as a very light overview of how you might create charts
1212
You will need the `seaborn` (python) and `ggplot2` (R) packages for this section.
1313

1414
```{r}
15-
#| eval: !expr F
15+
#| eval: false
1616
install.packages("ggplot2")
1717
```
1818

@@ -23,7 +23,7 @@ To install seaborn, pick one of the following methods (you can read more about t
2323
### System Terminal
2424

2525
```{bash}
26-
#| eval: !expr F
26+
#| eval: false
2727
pip3 install seaborn matplotlib
2828
```
2929

@@ -32,7 +32,7 @@ pip3 install seaborn matplotlib
3232
This package installation method requires that you have a virtual environment set up (that is, if you are on Windows, don't try to install packages this way).
3333

3434
```{r}
35-
#| eval: !expr F
35+
#| eval: false
3636
reticulate::py_install(c("seaborn", "matplotlib"))
3737
```
3838

@@ -41,7 +41,7 @@ reticulate::py_install(c("seaborn", "matplotlib"))
4141
In a python chunk (or the python terminal), you can run the following command. This depends on something called "IPython magic" commands, so if it doesn't work for you, try the System Terminal method instead.
4242

4343
```{python}
44-
#| eval: !expr F
44+
#| eval: false
4545
%pip install seaborn matplotlib
4646
```
4747

@@ -113,8 +113,8 @@ ggplot(hbcu_all, aes(x = Year, y = `4-year`)) + geom_line() +
113113

114114
```{python}
115115
#| label: line-graph-python-p9
116-
#| eval: !expr F
117-
#| include: !expr F
116+
#| eval: false
117+
#| include: false
118118
119119
ggplot(hbcu_all, aes(x = "Year", y = "4-year")) + geom_line() + \
120120
ggtitle("4-year HBCU College Enrollment")
@@ -161,14 +161,14 @@ hbcu_long = pd.melt(hbcu_all, id_vars = ['Year'], value_vars = hbcu_all.columns[
161161
#### Original Data
162162
```{r}
163163
#| label: pivot-operation-data
164-
#| echo: !expr F
164+
#| echo: false
165165
knitr::kable(head(hbcu_all))
166166
```
167167

168168
#### Long Data
169169
```{r}
170170
#| label: pivot-operation-data-2
171-
#| echo: !expr F
171+
#| echo: false
172172
173173
knitr::kable(head(hbcu_long))
174174
```
@@ -201,8 +201,8 @@ ggplot(hbcu_long, aes(x = Year, y = value, color = type)) + geom_line() +
201201
#### Python
202202
```{python}
203203
#| label: long-form-demo-python-p9
204-
#| eval: !expr F
205-
#| include: !expr F
204+
#| eval: false
205+
#| include: false
206206
207207
ggplot(hbcu_long, aes(x = "Year", y = "value", color = "variable")) + geom_line() + \
208208
ggtitle("HBCU College Enrollment") + \

0 commit comments

Comments
 (0)