Skip to content

Commit

Permalink
materials
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonpileggi committed Oct 26, 2022
1 parent dcaa994 commit 80d796f
Show file tree
Hide file tree
Showing 181 changed files with 17,791 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron
173 changes: 173 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

443 changes: 443 additions & 0 deletions README.html

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# debugging-nhsr
# Debugging in R for NHS-R

# When

Thursday 3rd November 2022

* GMT +1 02:00 pm – 5:00 pm

* EDT 10:00 am – 1:00 pm

# Where

This workshop will take place online.

# Pre-requisites

Knowledge of how to write a function in R.

# Learning objectives:

* Review code troubleshooting tips.

* Discuss debugging functions (traceback(), browser(), debug(), trace(), and recover()) and the additional benefits of employing some of these strategies within RStudio.

* Distinguish between strategies for debugging your own code versus someone else’s code

# Note

This workshop is limited to NHS employees and those who work in UK public
sector organisations such as PHE, local councils and DHSC.
17 changes: 17 additions & 0 deletions debugging-nhsr.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix
6 changes: 6 additions & 0 deletions demo/error-inspector-strsplit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
f <- function(x) { strsplit(x, ",") }
g <- function(x) { f(x) }

g(factor("a,b"))


19 changes: 19 additions & 0 deletions demo/error_inspector.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# IDE Error Inspector not triggered
f <- function(x) x + 1
g <- function(x) f(x)
g("a")

# IDE Error Inspector not triggered
strsplit(factor("a,b"), ",")

# IDE Error Inspector not triggered
f <- function(x) strsplit(x, ",")
f(factor("a,b"))

# IDE Error Inspector yes triggered
g <- function(x) f(x)
g(factor("a,b"))



options(error = recover)
6 changes: 6 additions & 0 deletions demo/error_recover.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source("demo/my_functions.R")
options(error = recover)
g("a")
options(error = NULL)


7 changes: 7 additions & 0 deletions demo/my_functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
f <- function(x) {
x + 1
}

g <- function(x) f(x)


29 changes: 29 additions & 0 deletions demo/trace-colSums.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

colSums(1:3)



trace(colSums, browser)
colSums(1:3)
# ls.str() in browser
untrace(colSums)



x <- as.list(body(colSums))
View(x)

# identify spot to insert code
as.list(x[[3]][[1]])
# equivalent notation
as.list(x[[c(3, 1)]])

# insert browser at step 3.1
trace(colSums, browser, at = list(c(3, 1)))
# execute function
colSums(1:3)
# ls.str() handy in browser
# cancel tracing
untrace(colSums)


3 changes: 3 additions & 0 deletions demo/warning.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
options(warn = 0) # default, warnings deferred to end
options(warn = 1) # print warning when it happens
options(warn = 2) # converts all warnings to errors, allows you to use regular debugging tools
Binary file added img/IDE_break-in-code.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/IDE_debug_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/IDE_debug_menu_crop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/IDE_debug_on-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/IDE_error-inspector.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/IDE_message-only.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/break-in-code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/breakpoint.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/butterflies.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/cheatsheet-debug-console.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/cheatsheet-interactive-debugger.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/colSums-body.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/colSums-list-investigate.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/colSums-list.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/console_break-in-code.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/console_error-inspector.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/console_message-only.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/debug_on-error.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/debugging-overview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/debugging.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/debugging_ide.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/debugging_pick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/debugging_special.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/debugging_theirs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/debugging_tools.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/debugging_yours.svg

Large diffs are not rendered by default.

Binary file added img/df_patient_characteristics_str_hl.png
Binary file added img/haystack.PNG
Binary file added img/interactive-debugger.PNG
Binary file added img/options-error-recover.PNG
Binary file added img/package-structure.PNG
Binary file added img/process-naked.jpg
Binary file added img/read-the-source-luke.PNG
Binary file added img/reprex-logo.png
Binary file added img/reprex-why.PNG
Binary file added img/rlang_last-error.PNG
Binary file added img/rlang_last-trace.PNG
Binary file added img/rstudio-ide.pdf
Binary file not shown.
Binary file added img/say_do.PNG
Binary file added img/source-marked.jpg
Binary file added img/source.PNG
Binary file added img/swat-bugs.gif
Binary file added img/traceback-ordering.PNG
Binary file added img/traceback.PNG
Binary file added img/usethis-cran-markup.png
Binary file added img/usethis-cran.png
Binary file added img/workspace-options.PNG
Binary file added img/wtf-logo-square-transparent.png
Loading

0 comments on commit 80d796f

Please sign in to comment.