-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rstats-wtf/update-examples
revise workshop examples
- Loading branch information
Showing
23 changed files
with
713 additions
and
195 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Origin ----------------------------------------------------------------------- | ||
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote | ||
# Object of type 'closure' is not subsettable, | ||
# https://github.com/jennybc/debugging | ||
|
||
|
||
# open 01_sourceme to inspect & review code --------------------------------------- | ||
# try file.edit() | ||
|
||
|
||
# source functions ------------------------------------------------------------- | ||
# source in 01_exercise/01_sourceme.R | ||
|
||
# view fruit data -------------------------------------------------------------- | ||
|
||
# successful execution --------------------------------------------------------- | ||
# confirm function works for berry | ||
fruit_avg(fruit, "berry") | ||
|
||
# error on execution ----------------------------------------------------------- | ||
# observe error | ||
fruit_avg(fruit, "peach") | ||
|
||
# identify location of error --------------------------------------------------- | ||
# try traceback() | ||
|
||
# copy and paste traceback results as a comment here to compare with next exercise | ||
|
||
|
||
# modify options for a richer traceback via rlang ------------------------------ | ||
|
||
# copy and paste traceback results as a comment here to compare with next exercise | ||
|
||
|
||
# interactive debugging -------------------------------------------------------- | ||
# enter interactive debugger by inserting browser() into the fruit_avg() function | ||
# trigger interactive debugger by executing function | ||
|
||
# use these commands at the Browse[]> prompt to navigate the debugger | ||
|
||
# | command | operation | | ||
# |---------|-------------------------| | ||
# | `n` | next statement | | ||
# | `c` | continue | | ||
# | `s` | step into function call | | ||
# | `f` | finish loop / function | | ||
# | `where` | show previous calls | | ||
# | `Q` | quit debugger | | ||
|
||
# while in the debugger, explore the objects in your environment | ||
# with ls.str() | ||
|
||
# Can you determine exactly why the bug is occurring? | ||
# If you have time, try to fix it! | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Origin ----------------------------------------------------------------------- | ||
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote | ||
# Object of type 'closure' is not subsettable, | ||
# https://github.com/jennybc/debugging | ||
|
||
|
||
# open sourceme to inspect & review code --------------------------------------- | ||
file.edit("01_exercise/01_sourceme.R") | ||
|
||
|
||
# source functions ------------------------------------------------------------- | ||
# open 01_exercise/01_sourceme.R and click on Source button | ||
# OR | ||
source("01_exercise/01_sourceme.R") | ||
|
||
|
||
# view fruit data -------------------------------------------------------------- | ||
fruit | ||
|
||
|
||
# successful execution --------------------------------------------------------- | ||
# confirm function works for berry | ||
fruit_avg(fruit, "berry") | ||
|
||
# error on execution ----------------------------------------------------------- | ||
# observe error | ||
fruit_avg(fruit, "peach") | ||
|
||
# identify location of error --------------------------------------------------- | ||
traceback() | ||
|
||
# copy and paste traceback results as a comment here to compare with next exercise | ||
|
||
|
||
# modify options for a richer traceback ---------------------------------------- | ||
options(error = rlang::entrace) | ||
fruit_avg(fruit, "peach") | ||
rlang::last_error() | ||
rlang::last_trace() | ||
|
||
# copy and paste traceback results as a comment here to compare with next exercise | ||
|
||
|
||
# interactive debugging -------------------------------------------------------- | ||
# enter interactive debugger by inserting `browser()` statement in | ||
# the fruit_avg() function in 01_sourceme.R | ||
# Restart R, re-source file | ||
source("01_exercise/01_sourceme.R") | ||
|
||
# trigger interactive debugger | ||
fruit_avg(fruit, "peach") | ||
|
||
# use these commands at the Browse[]> prompt to navigate the debugger | ||
|
||
# | command | operation | | ||
# |---------|-------------------------| | ||
# | `n` | next statement | | ||
# | `c` | continue | | ||
# | `s` | step into function call | | ||
# | `f` | finish loop / function | | ||
# | `where` | show previous calls | | ||
# | `Q` | quit debugger | | ||
|
||
# while in the debugger, explore the objects in your environment | ||
# with ls.str() | ||
|
||
# Can you determine exactly why the bug is occurring? | ||
# If you have time, try to fix it! | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Origin ----------------------------------------------------------------------- | ||
# This example was originally used inJenny Bryan's rstudio::conf(2020) keynote | ||
# Object of type 'closure' is not subsettable, | ||
# https://github.com/jennybc/debugging | ||
|
||
|
||
# open 01_sourceme to inspect & review code --------------------------------------- | ||
|
||
|
||
# source functions ------------------------------------------------------------- | ||
|
||
|
||
# view fruit data -------------------------------------------------------------- | ||
|
||
|
||
# successful execution --------------------------------------------------------- | ||
# confirm function works for berry | ||
fruit_avg(fruit, "berry") | ||
|
||
# error on execution ----------------------------------------------------------- | ||
# observe error | ||
fruit_avg(fruit, "peach") | ||
|
||
|
||
|
||
# identify location of error --------------------------------------------------- | ||
|
||
# copy and paste traceback results as a comment here to compare with next exercise | ||
|
||
|
||
|
||
# modify options for a richer traceback ---------------------------------------- | ||
|
||
|
||
# copy and paste traceback results as a comment here to compare with next exercise | ||
|
||
|
||
# interactive debugging -------------------------------------------------------- | ||
# enter interactive debugger | ||
|
||
# Can you determine exactly why the bug is occurring? | ||
# If you have time, try to fix it! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fruit <- data.frame( | ||
row.names = c("calories", "weight", "yumminess"), | ||
blackberry = c(4L, 9L, 6L), | ||
blueberry = c(1L, 2L, 8L), | ||
peach = c(59L, 150L, 10L), | ||
plum = c(30L, 78L, 5L) | ||
) | ||
|
||
fruit_avg <- function(dat, pattern) { | ||
cols <- grep(pattern, names(dat)) | ||
mini_dat <- dat[ , cols] | ||
message("Found ", ncol(mini_dat), " fruits!") | ||
rowMeans(mini_dat) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.