R Syntax

I mainly use R to manipulate and summarize data and it's my statistical software of choice. As a hobbyist programmer, each language has its quirks, but fundamentally, many are linked genealogically. Which is why, in the biostatistics world, I personally find R to be the most straightforward to learn syntactically. This is no fluke, of course; R is an implementation of the S language and both are influenced by other languages such as APL or Lisp. 

As an interesting example, you can see how these influences linger in the modern R environment we work with today, like this seeming redundancy:


The assignment operator “<-” is a consequence of influence from S. R actually only implemented “=” around 2001 to increase compatibility with S-Plus, C, Java, etc.

Now, why does this matter? Well, if you have experience with R, it probably doesn’t. You’ve probably gotten used to the syntax. But I find it useful to understand at how R handles its code; it'll save you a lot of time debugging large blocks of code. It can explain why this doesn’t work:


But this does (yes, y has been assigned the string as well), due to the hierarchy between the operators:


Or why this doesn’t work:

But these do (obviously the 2nd one isn’t recommended):