

This will avoid that someone gets a surprise while running the code because one of the imports is hidden in the middle of the code and the user did not prepare his environment for it. The first thing that should go into your R script are your libraries - the dependencies of your code should be explicit right at the beginning of it. So let’s jump right into some common best practices when it comes to R Programming (some are disputed, others are widely accepted by the community)!

And this is not exclusive to other people that you might have to work it, it will also spare your future self a lot of hassle (who never looked at their own code and thought: “ What the hell am I doing in this function?”)

The better organized your code is, the easier it will be for someone to look, debug and improve it in the future. And working collaboratively is one of the greatest skills to have when working as a data scientist, analyst (or almost any other profession)- if you want to make a career out of analyzing data, the probability that someone will have to look at your code in the future is probably 99.99%. When it comes to developing our code and scripts, we are not an island. Luckily, I’ve had the opportunity to work with a lot of engineers that have taught and explained me why code needs to be clean and efficient - if I can summarize that need in a sentence, the best one comes from John Donne’s poem(a saying almost 400 year old!): ‘No man is an island’. While thinking of distributions, statistics and other key concepts when analyzing data are natural to me, writing efficient and clean code is not. As someone with a background in statistics, I acknowledge the fact that I continuously have to improve my computer science and engineering skills, almost every day.
