Skip to content

Commit 97dce4d

Browse files
update spartan and comfy scripts
1 parent 481642e commit 97dce4d

File tree

6 files changed

+364
-0
lines changed

6 files changed

+364
-0
lines changed

01_exercise/01_debugging_comfy.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1+
# Origin -----------------------------------------------------------------------
2+
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote
3+
# Object of type 'closure' is not subsettable,
4+
# https://github.com/jennybc/debugging
5+
6+
7+
# open 01_sourceme to inspect & review code ---------------------------------------
8+
# try file.edit()
9+
10+
11+
# source functions -------------------------------------------------------------
12+
# source in 01_exercise/01_sourceme.R
13+
14+
# view fruit data --------------------------------------------------------------
15+
16+
# successful execution ---------------------------------------------------------
17+
# confirm function works for berry
18+
fruit_avg(fruit, "berry")
19+
20+
# error on execution -----------------------------------------------------------
21+
# observe error
22+
fruit_avg(fruit, "peach")
23+
24+
# identify location of error ---------------------------------------------------
25+
# try traceback()
26+
27+
# copy and paste traceback results as a comment here to compare with next exercise
28+
29+
30+
# modify options for a richer traceback via rlang ------------------------------
31+
32+
# copy and paste traceback results as a comment here to compare with next exercise
33+
34+
35+
# interactive debugging --------------------------------------------------------
36+
# enter interactive debugger by inserting browser() into the fruit_avg() function
37+
# trigger interactive debugger by executing function
38+
39+
# use these commands at the Browse[]> prompt to navigate the debugger
40+
41+
# | command | operation |
42+
# |---------|-------------------------|
43+
# | `n` | next statement |
44+
# | `c` | continue |
45+
# | `s` | step into function call |
46+
# | `f` | finish loop / function |
47+
# | `where` | show previous calls |
48+
# | `Q` | quit debugger |
49+
50+
# while in the debugger, explore the objects in your environment
51+
# with ls.str()
52+
53+
# Can you determine exactly why the bug is occurring?
54+
# If you have time, try to fix it!
55+
56+
157

258

01_exercise/01_debugging_spartan.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Origin -----------------------------------------------------------------------
2+
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote
3+
# Object of type 'closure' is not subsettable,
4+
# https://github.com/jennybc/debugging
5+
6+
7+
# open 01_sourceme to inspect & review code ---------------------------------------
8+
9+
10+
# source functions -------------------------------------------------------------
11+
12+
13+
# view fruit data --------------------------------------------------------------
14+
15+
16+
# successful execution ---------------------------------------------------------
17+
# confirm function works for berry
18+
fruit_avg(fruit, "berry")
19+
20+
# error on execution -----------------------------------------------------------
21+
# observe error
22+
fruit_avg(fruit, "peach")
23+
24+
25+
26+
# identify location of error ---------------------------------------------------
27+
28+
# copy and paste traceback results as a comment here to compare with next exercise
29+
30+
31+
32+
# modify options for a richer traceback ----------------------------------------
33+
34+
35+
# copy and paste traceback results as a comment here to compare with next exercise
36+
37+
38+
# interactive debugging --------------------------------------------------------
39+
# enter interactive debugger
40+
41+
# Can you determine exactly why the bug is occurring?
42+
# If you have time, try to fix it!
43+

02_exercise/02_debugging_comfy.R

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Origin -----------------------------------------------------------------------
2+
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote
3+
# Object of type 'closure' is not subsettable,
4+
# https://github.com/jennybc/debugging
5+
6+
# Restart R!
7+
8+
# open 02_sourceme to inspect & review code ---------------------------------------
9+
# the content is essentially the same as 01_exercise, but the code has been re-structured
10+
# try file.edit()
11+
12+
13+
# source functions -------------------------------------------------------------
14+
# source in 02_exercise/02_sourceme.R
15+
16+
# view fruit data --------------------------------------------------------------
17+
18+
19+
# successful execution ---------------------------------------------------------
20+
# confirm function works for berry
21+
fruit_avg(fruit, "berry")
22+
23+
# error on execution -----------------------------------------------------------
24+
# observe error
25+
fruit_avg(fruit, "peach")
26+
27+
# identify location of error via traceback -------------------------------------
28+
# try traceback()
29+
30+
# copy and paste traceback results as a comment here to compare with other exercises
31+
32+
33+
# modify options for a richer traceback via rlang ------------------------------
34+
35+
36+
# copy and paste traceback results as a comment here to compare with other exercises
37+
38+
# How do the tracebacks look different compared to 01_exercise?
39+
40+
# interactive debugging via IDE ------------------------------------------------
41+
# Restart R
42+
# enter interactive debugger by inserting a breakpoint in
43+
# the fruit_avg() function in 02_sourceme.R
44+
# re-source file
45+
# trigger interactive debugger by executing the function
46+
47+
# navigate the debugger using the buttons at the top of the console
48+
# be sure to try the "step into" option!
49+
50+
# while in the debugger, explore the objects in your environment
51+
# with ls.str()
52+
53+
54+
# interactive debugging via IDE, again -----------------------------------------
55+
# Remove breakpoint from 02_sourceme.R
56+
# Restart R
57+
# Modify IDE settings to Debug -> On Error -> ??
58+
# re-source in the file
59+
60+
# trigger console error inspector by executing the function
61+
62+
# explore the "Show Traceback" and "Rerun with Debug" options
63+
# Where does the debugger drop you in?
64+
65+
# Can you determine exactly why the bug is occurring?
66+
# If you have time, try to fix it!
67+
68+

02_exercise/02_debugging_spartan.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Origin -----------------------------------------------------------------------
2+
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote
3+
# Object of type 'closure' is not subsettable,
4+
# https://github.com/jennybc/debugging
5+
6+
# Restart R!
7+
8+
# open 02_sourceme to inspect & review code ---------------------------------------
9+
# the content is essentially the same as 01_exercise, but the code has been re-structured
10+
11+
12+
13+
# source functions -------------------------------------------------------------
14+
# source in 02_exercise/02_sourceme.R
15+
16+
# view fruit data --------------------------------------------------------------
17+
18+
19+
# successful execution ---------------------------------------------------------
20+
# confirm function works for berry
21+
fruit_avg(fruit, "berry")
22+
23+
# error on execution -----------------------------------------------------------
24+
# observe error
25+
fruit_avg(fruit, "peach")
26+
27+
# identify location of error ---------------------------------------------------
28+
29+
# copy and paste traceback results as a comment here to compare with other exercises
30+
31+
32+
# modify options for a richer traceback ----------------------------------------
33+
34+
# copy and paste traceback results as a comment here to compare with other exercises
35+
36+
# How do the tracebacks look different compared to 01_exercise?
37+
38+
# interactive debugging via IDE ------------------------------------------------
39+
# Restart R
40+
# enter interactive debugger by inserting a breakpoint in
41+
# the fruit_avg() function in 02_sourceme.R
42+
43+
44+
45+
46+
# interactive debugging via IDE, again -----------------------------------------
47+
# Remove breakpoint from 02_sourceme.R
48+
# Restart R
49+
# Modify IDE settings to Debug -> On Error -> ??
50+
51+
# explore the "Show Traceback" and "Rerun with Debug" options
52+
# Where does the debugger drop you in?
53+
54+
55+
# Can you determine exactly why the bug is occurring?
56+
# If you have time, try to fix it!

03_exercise/03_debugging_comfy.R

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Origin -----------------------------------------------------------------------
2+
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote
3+
# Object of type 'closure' is not subsettable,
4+
# https://github.com/jennybc/debugging
5+
6+
# Restart R!
7+
8+
# install the wtfdbg package ---------------------------------------------------
9+
# the content is essentially the same as 02_exercise, but now the code is no
10+
# longer yours!
11+
# install.packages("devtools")
12+
devtools::install_github("rstats-wtf/wtfdbg")
13+
14+
15+
# attach package ---------------------------------------------------------------
16+
17+
18+
# view fruit data --------------------------------------------------------------
19+
20+
# successful execution ---------------------------------------------------------
21+
# confirm function works for berry
22+
fruit_avg(fruit, "berry")
23+
24+
# error on execution -----------------------------------------------------------
25+
# observe error
26+
fruit_avg(fruit, "peach")
27+
28+
# identify location of error via traceback -------------------------------------
29+
30+
31+
# copy and paste traceback results as a comment here to compare with other exercises
32+
33+
34+
# modify options for a richer traceback via rlang ------------------------------
35+
36+
# copy and paste traceback results as a comment here to compare with other exercises
37+
38+
39+
# How do the tracebacks look different compared to 02_exercise?
40+
41+
42+
# interactive debugging via debugonce() ----------------------------------------
43+
# set interactive debugger
44+
45+
# trigger interactive debugger
46+
47+
48+
# navigate the debugger using the buttons at the top of the console
49+
# be sure to try the "step into" option!
50+
51+
# while in the debugger, explore the objects in your environment
52+
# with ls.str()
53+
54+
55+
# interactive debugging via recover error option--------------------------------
56+
# options(? = ?)
57+
58+
# trigger recover
59+
60+
# explore the frames
61+
62+
# reset options
63+
64+
65+
66+
# interactive debugging via trace() --------------------------------------------
67+
68+
# investigate the function body with as.list() + body()
69+
70+
# identify a function step to enter debugger
71+
72+
73+
# insert browser statement at specified step
74+
75+
# trigger trace
76+
77+
# try ls.str() to get your bearings
78+
# and s, s, s, to keep stepping through functions
79+
80+
# cancel tracing
81+
82+
83+
# Can you determine exactly why the bug is occurring?
84+
# If you have time, try to fix it!
85+
86+

03_exercise/03_debugging_spartan.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Origin -----------------------------------------------------------------------
2+
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote
3+
# Object of type 'closure' is not subsettable,
4+
# https://github.com/jennybc/debugging
5+
6+
# Restart R!
7+
8+
# install the wtfdbg package ---------------------------------------------------
9+
# the content is essentially the same as 02_exercise, but now the code is no
10+
# longer yours!
11+
# install.packages("devtools")
12+
devtools::install_github("rstats-wtf/wtfdbg")
13+
14+
15+
# attach package ---------------------------------------------------------------
16+
17+
18+
# view fruit data --------------------------------------------------------------
19+
20+
# successful execution ---------------------------------------------------------
21+
# confirm function works for berry
22+
fruit_avg(fruit, "berry")
23+
24+
# error on execution -----------------------------------------------------------
25+
# observe error
26+
fruit_avg(fruit, "peach")
27+
28+
# identify location of error ---------------------------------------------------
29+
30+
31+
# copy and paste traceback results as a comment here to compare with other exercises
32+
33+
34+
# modify options for a richer traceback ----------------------------------------
35+
36+
# copy and paste traceback results as a comment here to compare with other exercises
37+
38+
39+
# How do the tracebacks look different compared to 02_exercise?
40+
41+
42+
# interactive debugging via debugonce() ----------------------------------------
43+
44+
45+
46+
# interactive debugging via recover error option--------------------------------
47+
48+
49+
50+
# interactive debugging via trace() ----------------------------------------------
51+
52+
53+
54+
# Can you determine exactly why the bug is occurring?
55+
# If you have time, try to fix it!

0 commit comments

Comments
 (0)