Good practices

To ensure a working, shareable and (re)readable code, anyone working with R should follow some good practices.

Clean up the console

When working with RStudio, RStudio stores all the variables in the memory. For consistency, I believe it is safer to clean all those variable before launching any new, unrelated R code.

To do so:

closeAllConnections()
rm(list=ls())

Comment! Comment! Comment!

Good commenting allows the code to be readable by others, and by oneself when some time has passed.

RStudio

Use RStudio!