DEV Community

Rohit Farmer
Rohit Farmer

Posted on

Learning R: Rant 2

Continuing my rant series while I am learning R. R is pretty much like Perl in terms of the philosophy that they follow; that is "There Is More Than One Way To Do It (TIMTOWTDI)". Although I appreciate this philosophy as it opens up the possibility of adopting multiple ways of doing the same thing. It becomes problematic when multiple people are working on the same project or worse if you are taking over someone else's project. Understanding the code becomes a pain in the back. Python, in this case, is a good language because it is more readable to a human and there are pretty much-set things on how to solve a particular kind of problem. Packages in R also have too many overlapping functions that mask each other in the order the packages are loaded. Therefore, you always need to be cautious about a function's source before calling it.

Top comments (1)

Collapse
 
daveparr profile image
Dave Parr

Ha. I like this one.

Yes. No one ever wrote the 'Zen of R' (or at least wrote it in time to impact the core language). I think this just has to be a human managed thing. Again, as per your last post, which I also agree with, use tidyverse.

It's been designed specifically to be consistent and in some opinions 'human readable'.

Pipes! now you read left to right, no nesting. How human :)
Only functions that get masked are from base, tidyverse doesn't internally mask itself because it's written by the same devs (RStudio).

Also if you're working in a team with people, it's always useful to settle on 'conventions'. I think you could probably argue that you could do things in multiple ways in python. e.g. how many plotting libraries are there? Seaborn, plotly, matplotlib and bokeh all sort have a take on it. Admittedly in R we have a few ways to skin the cat, but if you put ggplot code in-front of someone who's used R in the last 10 years, they will get it immediately.

Pain points I do see a lot though still:

  • using the dollar sign to reference a column in a table. Really shouldn't be done any more IMHO
  • understanding the difference between [x] and [[x]]
  • confusing intermediate assignment

And my pet one:

  • package management It's gone so far on this that we're learning from python as some of the core devs have started renv