ποΈ Week 02 β Day 01: Neat functions, testing and debugging
What good code looks like and how to test it
Learn to spot opportunities to write functions and how to write them well. Weβll also learn how to test our code and how to debug it when things go wrong.
- Object-Oriented vs Functional Programming
- How to organise your code
- Prototyping vs βProductionβ mode
- Code βlintingβ and documentation
π¨βπ« Lecture Notes
Today we have a mix of slides and practical coding exercises.
π₯ Looking for lecture recordings? You can only find those on Moodle.
1st Hour - Debugging & Refactoring
Either click on the slide area below or click here to view it in fullscreen. Use your keypad to navigate the slides.
2nd Hour - R package, testing and documentation
Letβs create an R package together. Weβll use it to organise our code to adhere to the R package convention.
We will practice writing functions and testing them, then we will see how to document and lint our code.
3rd Hour - π¦Έ Super Tech Support
I will be available to help you apply these best practices into your midterm assignment code.
π Recommended readings & Revision
Our number 1 suggestion is for you to complete the midterm assignment.
Also check the documentation of the packages we used today:
lintr
,roxygen2
,devtools
,testthat
.Check the tidyverse style guide for more details on how to write good code.
(Optional Readings)
- (Wickham 2019, chaps. 12β16) - Advanced R, by Hadley Wickham (chapters on Object-Oriented Programming)
- (Peng 2014, chap. 16) - R Programming for Data Science, by Roger D. Peng (chapter on Loop Functions in R)
- (Burns 2011) - R Inferno, by Patrick Burns (a book on common R mistakes and how to avoid them)