
The R programming language for programmers - Anon84
http://www.johndcook.com/R_language_for_programmers.html
======
jbr
R is one of my favorite tools and I heartily recommend it to any hacker for
data visualization alone. I've used R to make sense of high-n high dimensional
data and it's a delight (even if the syntax takes a little getting used to).

As Buckwild said, best way to learn R is by messing around with it; There's
in-editor help and a REPL. Download the GUI for your OS, not just the command-
line tool; it has nice package management and graphical output (to a quartz
window in os x).

If you're thinking of using R for plotting as well as analysis, I heartily
_heartily_ recommend the ggplot2 package. ( <http://had.co.nz/ggplot2/> ) --
there's a lively google group for support and the output is far better than
comparable packages (like lattice, my second favorite).

The other famous book for R isn't actually for R -- it's for S.
<http://www.stats.ox.ac.uk/pub/MASS4/> R is the open-source superset
implementation of S/S-plus.

Download R and give it a shot: <http://cran.r-project.org/mirrors.html>

~~~
tel
I want to recommend all of Hadley Wickham's R packages, actually. Ggplot2 is
one of the best R plotting packages around, easily, but --- since one of the
biggest initial problems with learning R is figuring out how to use the 20-or-
so built-in functions to manipulate data to the right shape --- I have to
doubly-recommend Plyr and Reshape as well.

I think that's the real way to learn R. Play with it until you're thoroughly
frustrated, then download a few packages like Reshape and learn them. They'll
probably have better documentation and typically have some really specific use
cases which will help you understand how to use R toward its strengths.

~~~
hadley
Thanks!

------
buckwild
Its a nice post but its still my contention that the best method by which to
learn any language is the "There ain't nothin' to it but to do it" method.
That is, to learn by experimenting with the language and by trial and error.

I picked up R 2 weeks ago at work. I didn't know anything about it and I
sucked at using it. I am proud to say that after 2 weeks of hard work, cursing
at the computer monitor and beating my head against the cubicle wall, I am
dramatically better than I was-- comparable to the experienced R programmers
who work here.

~~~
cruise02
> its still my contention that the best method by which to learn any language
> is the "There ain't nothin' to it but to do it" method.

Absolutely true, but you still need _something_ to read to introduce you to
the basic syntax and the general concepts of the language. Having a bridge
between a known language and a new language can significantly speed this phase
up, and get you quickly to the point where you're able to start experimenting.

~~~
jordyhoyt
Right. I briefly used R for research while I was in school. It was definitely
a valuable tool for generating sets of random numbers, doing some statistical
operations on them (PCA and SVD if you must know), and outputting them to a
file that I could then pipe to my C program. It was a good example of doing
one thing and doing it [pretty] well.

That said, I only learned enough of R to get it to do what I wanted. The help
in the interactive mode was all I really had to go off of then, and that was
very helpful with plenty of examples. Being a relatively uncommon, single-
letter language name, google wasn't giving me anything useful at the time. I
see that is now much improved now, but this tutorial - mapping it to other
languages and explaining syntax gotchas - would have saved me several hours of
ramp-up for the simple tasks I wanted to accomplish.

------
jackdawjack
Good resource, i had to start using R recently and most of the examples and
books i found were of the "stats with R" variety which all emphasise how to
just roll along with the library functions. The general advice i got from some
statisticians was to find someone else's code that kind of works and
copy|paste. Blurg

The official help docs are very good, also the extensions guide is pretty
vital if you're linking to c etc. <http://cran.r-project.org/manuals.html>

Also the ESS(emacs speaks statistics) extension is really really good, well
certainly if you're doing something statisticy with R.

------
shaunxcode
wow - the first couple of paragraphs make it seem like brainfck! I love the
part about using . for multi word variables because in a past version of a
previous language _ was used for assignment! And thus the . can not be used
for methods and instead they use $. holy crap. Yet somehow I am still
strangely intrigued in a "this is as close to APL as I am going to get with
out a magic keyboard" sort of way.

~~~
dazmax
If you really want the APL experience, try J
(<http://www.jsoftware.com/help/dictionary/vocabul.htm>)

~~~
shaunxcode
when I was looking into apl-esque paradigms the coolest thing I stumbled upon
was a language called nial<http://en.wikipedia.org/wiki/Nial> \- very clean
and really good use of syntax! I am going to check out J for sure though -
thanks.

------
andreas_s
A more comprehensive tutorial for programmers:
<http://heather.cs.ucdavis.edu/~matloff/R/RProg.pdf>

------
bayareaguy
I'd recommend people who work with PostgreSQL also take a look at PL/R[1] and
RPostgreSQL[2].

1- <http://www.joeconway.com/plr>

2-
[http://cran.r-project.org/web/packages/RPostgreSQL/index.htm...](http://cran.r-project.org/web/packages/RPostgreSQL/index.html)

------
p_h
Thanks for the link, I'm just starting out in R, coming from Python and C++,
so the article is perfect for me.

~~~
jacobolus
If you haven't tried it already, I recommend you take a look at NumPy, which
is the Python module for doing array math. R is great, but as a Python
programmer, I really prefer staying in Python to using R or Matlab for
numerical stuff.

It doesn't have quite the shortcuts for making basic stuff completely trivial
(in the 10-50 LOC range), but for anything with more structure, I find it
generally works out better in the end.

------
mrshoe
This is a good article, but the very first example is perhaps a bit ill-
chosen. The mass-energy equivalence formula doesn't _assign_ mc^2 to e, it
_states that the two sides are always equal_. The equality operator (== in C),
would probably be more appropriate.

------
cpettitt
I also found this to be a good intro to R:
<http://cran.r-project.org/doc/contrib/Verzani-SimpleR.pdf>

------
gchpaco
R is a superb prototyping language for statistical work, but making it work
right for batch work is unnecessarily difficult IMHO. Still, an immensely
useful tool.

------
joe_the_user
_It is sometimes possible to use = for assignment, though I don't understand
when this is and is not allowed. Most people avoid the issue by always using
the arrow._

Somehow this does not seem like an auspicious starting statement!

~~~
jacobolus
In a couple of semesters writing medium-complexity R programs, I never had any
problems using = for assignment. I'd recommend it, as it's much easier to type
than <-, and looks more natural coming from a programming background.

~~~
joe_the_user
Yes, but do you _know_ the rules for when this is or isn't allowed?

I guess I come from a background of looking at big applications and finding
points failure where someone did something that would "probably work" - ie, it
works till you allocate 5 megs of memory or....

~~~
jacobolus
I think the issue is assignment in R is an expression rather than a statement
(I think), but there are some other places where '=' gets used for different
syntax, and you always use <\- for assignment, even in those situations. For
me, it doesn't come up, because as a Python programmer I've fully bought into
the idea that assignment should be a statement, and so I don’t try to use it
as an expression in code. If you’re used to Python, then you’ll be used to
seeing "=" for both assignment and keyword function arguments, so there’s no
real confusion.

I've never had a problem, but again, I've never tried to write R libraries for
public consumption, or hack on large chunks of existing R code, so YMMV.

------
pageman
thanks for this - exploring how R is vs. Statistica

