Surviving and enjoying R part 1

Intro

R may appear as a dreadful programming language, especially if you are coming from computer science background. Having said that, there is no doubt that R is a brilliant tool for interactive data analysis.

Or as my friend puts it: “The difference between R and Python is that R was designed by statisticians who knew a bit of programming while Python was designed by programmers who knew a bit of statistics.”

We do not think it matters that much how good, expressive or fast is R as a programming language. The real comparative advantage of R lies in a huge and active community of users and developers, nearly infinite universe of high quality packages and easily accessible online resources that are on your finger tips for free. Be as it may, in this article we would like to give you an advice how to take advantage of R in practice and survive. The purpose of this document is not to serve as an introduction to R’s syntax, therefore you will not find here sections like How to concatenate vectors in R or similar. Rather than that, this mini series should help you feel more comfortable during your work with R, speed-up your analyses and avoid mistakes and inefficiencies we had to overcome the hard way. Regardless if you are taking your first steps with R or you are already an experienced R user we belive you will find here relevant advice or at least an inspiration.

Coding etiquette

In a typical data science workflow there is not as great pressure on code refactoring, readability, testing and expressivity as in a full-blown software development. Though, it is worth following at least the basic rules of coding etiquette, especially if it is a collaborative project or a code that goes into a production. For R specifically there are two really well designed style guides:

Personally I prefer the later one. Also, naming convention for files, functions or variables should be agreed at the beginning of every project. You might consider using code linting tools (e.g. lintr) that can help you with making your code nice and readable. Last but not the least: comment your code! You can trust us that your investment of time and effort into a nice and readable code will pay off. (more…)