14.4 How to write good code/workflow!

  • Q: What is your experience with looking at data analysis code you have written 2 years earlier?
  1. Comment your code
    • Data sources, data manipulations, describe steps of analysis
    • commenting increases readability
    • commenting increases reproducability
    • you can’t comment too much
    • Comments in R: #
    • Use meaningful names!
    • Don’t be too clever!
  2. Structure you code properly
  3. More rules
    • Code must be usable on machines with different paths to the project
      • Path is set once and afterwards, relative paths are used
      • There is a folder structure separating data and figures (and code)

For larger projects you might consider tools that keep track of versions, branches etc. like Git (http://www.github.com among others offers free git repositories). github can easily be used from within RStudio.

  1. More…