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:
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....
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

andrewsw
24 September 2014 - 06:22 AM
Pascal has :=, I suppose <- is a little better(?), a little more indicative.
But, R assignment operators:
where x is a variable name possibly quoted.
Curiouser and curiouser.
But, R assignment operators:
Quote
x <- value
x <<- value
value -> x
value ->> x
x = value
x <<- value
value -> x
value ->> x
x = value
where x is a variable name possibly quoted.
Curiouser and curiouser.
Page 1 of 1
Trackbacks for this entry [ Trackback URL ]
← January 2021 →
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)