Preparing your defences

Defensive R Programming

Dr. Colin Gillespie

Jumping Rivers

Preparing your defenses

The wise warrior avoids the battle.

? Sun Tzu, The Art of War

Avoid problems!

  • We all make mistakes
  • Let's minimise the number!
Defensive R Programming

Are you wet or dry

  • DRY: a standard principle of software development
    • Do not repeat yourself
  • WET: write everything twice
    • We enjoy typing
Defensive R Programming

The copy and paste rule

  1. Copying and pasting once is OK
  2. Twice is suspect
  3. Three times is almost always wrong
Defensive R Programming

Functions and for loops

Whenever you copy & paste

  • A function
  • Or a for loop
Defensive R Programming

Let's see this in action

Defensive R Programming

Preparing Video For Download...