Subscribe to ...considered harmful        RSS Feed
***** 2 Votes

Some Notes On R: A Dialog

Icon 2 Comments
When beginning R, the user should expect a number of gasps of disbelief, face-palm moments will not be uncommon, and occasionally the responsible programmer will be tempted to take the language out back and shoot it in the head.

I'll get much of this reaction out of the way for you in one line:

spam.df <-data.frame(cbind(names(spam.counts), as.numeric(spam.counts)),stringsAsFactors=FALSE)

The following conversation might reasonably ensue, when this line is first encountered, if only in your head:

Q: Hm. Does the period in "spam.df" indicate any sort of "selector" operator? Are we looking at a thing called "spam" which has an element called "df"?
A: No, and no. We are looking at a period character which is simply another character, and therefore spam.df has no relation at all to, say, "spam.counts". (it turns out that we can select elements of an object with the $ operator... I suppose R just has to be different)
Q: So I suppose that we always use the . to separate words in variable names?
A: No, I'm afraid not. Other language primitives use dromedaryCase (as in "stringsAsFactors") and still others use underscore separators.
Q: Oh. Still, I suppose there must be some rational system in place, so this confusion ends up telling me something?
A: Sad to say, but there isn't. It's pretty much arbitrary, and not even consistently applied within a given library - or even the arguments to a particular function.
Q: Oh. And function arguments are named?
A: Yes, generally. So you have to remember the arbitrarily-chosen convention each and every time you call that function.
Q: What fun.
A: But wait, there's more!
Q: Great god in boots, is that actually a left arrow being used as an assignment operator?
A: Yes. Yes, it is. Two keystrokes, and an awkwardly placed combination to boot, for one of the most commonly-used operators in a language.
Q: Oh, dear.
A: And we've only just begun.

To be continued....

2 Comments On This Entry

Page 1 of 1


24 September 2014 - 06:22 AM
Pascal has :=, I suppose <- is a little better(?), a little more indicative.

But, R assignment operators:


x <- value
x <<- value
value -> x
value ->> x

x = value

where x is a variable name possibly quoted.

Curiouser and curiouser.


12 January 2016 - 03:20 PM
F'n right hand assignment operators.
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

May 2022

151617 18 192021


    Recent Entries

    Recent Comments

    Search My Blog

    1 user(s) viewing

    1 Guests
    0 member(s)
    0 anonymous member(s)