Week 6 (April 18)

Don’t repeat yourself (DRY) is a software development principle aimed at reducing repetition. Formulated by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer, the DRY principle states that “every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” This principle has been widely adopted to imply that you should not duplicate code. Although the principle was meant to be far grander than that, there’s plenty of merit behind this slight misinterpretation.

Removing duplication is an important part of writing efficient code and reducing potential errors. First, reduced duplication of code can improve computing time and reduces the amount of code writing required. Second, less duplication results in less creating and saving of unnecessary objects. Inefficient code invariably creates copies of objects you have little interest in other than to feed into some future line of code; this wrecks havoc on properly managing your objects as it basically results in a global environment charlie foxtrot! Less duplication also results in less editing. When changes to code are required, duplicated code becomes tedious to edit and invariably mistakes or fat-fingering occur in the cut-and-paste editing process which just lengthens the editing that much more.

Thus, minimizing duplication by writing efficient code is important to becoming a data analyst and this week we will focus on two methods to achieve this:

  1. Writing functions
  2. Using iteration

Assignments

  • Your final project is due by 11:59PM, April 26, 2020. Other than completing the final project, there are no additional homework assignments.
  • .Rmd files may take much longer to knit and render than you think. Anticipate and plan for potential delays!
  • Refer to the final project page to know what to submit and how to submit everything.
  • Unless you have large files to send in addition to the data sets that are provided on the course website and need to email everything, please submit your final project URL and any necessary files in a private message via Slack.
  • Please include your name(s) in the YAML.

Readings

  • Optional (i.e., not mandatory) reading: Refer to the Week 7 page of the course website for machine learning with the Tidyverse.

Class

Please download this material for Saturday’s class: