[R] questions on some operators in R

Erik Iverson eriki at ccbr.umn.edu
Fri Jun 18 23:45:44 CEST 2010


Horace Tso wrote:
> You still couldn't sway me into the <- camp. '=' is better for yet
> two more reasons,
> 
> 1. it requires one keystroke, rather than two,
> 
> 2. to type '<', one has to hold Shift then the ',' key, so it's a
> total of three strokes all together.

This is a valid point.

You can, however, configure your editor to automatically do this sort of 
thing.  For example, ESS for Emacs has 'ess-toggle-underscore', which 
upon typing an underscore, will insert ' <- ' by default.

So compare:

x = y at 5 keystrokes using no keyboard shortcuts

vs.

x <- y at 4 keystrokes using the ESS default (counting '_' as 2 keystrokes)

I prefer binding M-= rather than underscore to invoke this behavior, 
still two keystrokes, but more natural to me.

> In a typical script, you have hundreds of assignment statements.
> Those extra keystroke translate into quite a bit more wear on your
> fingers.

In one R package I wrote here at work, I have:

'<-' assignments / total characters
956 / 96387
[1] 0.00991835

So, without keyboard shortcuts, I could have saved about 1000 characters 
over the development time of this package.  Compare to this email, which 
contains over 1100 characters.  :)



More information about the R-help mailing list