The Traveller's Last Journey DEDICATED TO SHAI MAROM Z"L

First impressions of R

F

I’ve only been studying R[I] for a few weeks. It’s my second programming language, and I’m only a beginner at my first – python.

R is strangely strange. It looks a bit like java with all its brackets, but then goes and uses “<-” for designating variables, as if the universal “=” wasn’t good enough. In my accumulation of anecdotal evidence, I explain some of these superficial characteristics as effects of the R’s creation ethos: be a language for non-programmer statisticians, whilst allowing them to use it as a sophisticated language relative to their position on the learning curve.

I’m sure there are many differences but a few have stood out more than others to these eye’s first impression:

(A) Writing in R is more dynamic. You can kinda write some variables and functions, and then run them, thereby loading them into the environment. Once they’re in the environment you can keep playing with them, going back and forth between the code and the shell, perhaps re-running a function if it has been edited, so as to update its reference in the environment.

(B) R doesn’t have objects. But it has functions that act like objects. Technically they’re S3 and S4 objects, but from my perspective, it seems to depend on some memory disposal hijinks. In R, function return their last statement, and their internal variables normally thereafter destroyed. But if the returning statement of a function contains pointers to variables within the function, then the memory is not recycled, and the internal variables (including functions) can be referenced as if that function were an object.

(C) The variable types are different. There are still character, boolean, and numeric variable types, but arrays are now organized depending on the uniformity of a set’s data types – in which case it can form a vector, or else a list, which can be labelled in the manner of a dictionary. The common use of vectors vs lists vs data.frames and the implications and translation from one to the other is very different from Python where typing is often (not always) ignored.

(D) Some of the argument parameters in R seem confusingly flexible. The most obvious instance of this is the use of data.frame filter() that can accept a literal name of column (e.g. name_of_col), or a literal column (e.g. [df[[name_of_col]). This confuses me because its not clear when and how keyword arguments are identified, and when an optional keyword argument can use a variable name (e.g. in the case of conditions when using subset() to test a column name identified by a variable). My thinking at this stage is that it may not matter, that it may have to do with scoping rules (which are different in R to python) and that it may have to do with mechanics of the magic that occurs behind the scenes.

[I] R is a programming language and free software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developing statistical software and data analysis”. For further details see https://en.wikipedia.org/wiki/R_(programming_language).

Print Friendly, PDF & Email

About the author

Add comment

By Pala
The Traveller's Last Journey DEDICATED TO SHAI MAROM Z"L

Search by Category

Search by Date

Shai