[R] Learning the R way – A Wish
David Winsemius
dwinsemius at comcast.net
Tue Mar 5 01:58:59 CET 2013
On Mar 4, 2013, at 3:42 PM, andrewH wrote:
> There is something that I wish I had that I think would help me a lot to be a
> better R programmer, that I think would probably help many others as well.
> I put the wish out there in the hopes that someone might think it was worth
> doing at some point.
>
> I wish I had the code of some substantial, widely used package – lm, say –
> heavily annotated and explained at roughly the level of R knowledge of
> someone who has completed an intro statistics course using R and picked up
> some R along the way. The idea is that you would say what the various
> blocks of code are doing, why the authors chose to do it this way rather
> than some other way, point out coding techniques that save time or memory or
> prevent errors relative to alternatives, and generally, to explain what it
> does and point out and explain as many of the smarter features as possible.
> Ideally, this would include a description at least at the conceptual level
> if not at the code level of the major C functions that the package calls, so
> that you understand at least what is happening at that level, if not the
> nitty-gritty details of coding.
>
> I imagine this as a piece of annotated code, but maybe it could be a video
> of someone, or some couple of people, scrolling through the code and talking
> about it. Or maybe something more like a wiki page, with various people
> contributing explanations for different lines, sections, and practices.
>
> I am learning R on my own from books and the internet, and I think I would
> learn a lot from a chatty line-by-line description of some substantial block
> of code by someone who really knows what he or she is doing – perhaps with a
> little feedback from some people who are new about where they get lost in
> the description.
>
> There are a couple of particular things that I personally would hope to get
> out of this. First, there are lots of instances of good coding practice
> that I think most people pick up from other programmers or by having
> individual bits of code explained to them that are pretty hard to get from
> books and help files. I think this might be a good way to get at them.
>
> Second, there are a whole bunch of functions in R that I call
> meta-programming functions – don’t know if they have a more proper name.
> These are things that are intended primarily to act on R language objects or
> to control how R objects are evaluated. They include functions like call,
> match.call, parse and deparse, deparen, get, envir, substitute, eval, etc.
> Although I have read the individual documentation for many of these command,
> and even used most of them, I don’t think I have any fluency with them, or
> understand well how and when to code with them. I think reading a
> good-sized hunk of code that uses these functions to do a lot of things that
> packages often need to do in the best-practice or standard R way, together
> with comments that describe and explain them would help a lot with that.
> (There is a good smaller-scale example of this in Friedrich Leisch’s
> tutorial on creating R packages).
>
> These are things I think I probably share with many others. I actually have
> an ulterior motive for suggesting lm in particular that is more peculiar to
> me, though not unique I am sure. I would like to understand how formulas
> work well enough to use them in my own functions. I do not think there is
> any way to get that from the help documentation. I have been working on a
> piece of code that I suspect is reinventing, but in an awkward and kludgey
> way, a piece of the functionality of formulas. So far as I have been able to
> gather, the only place they are really explained in detail is in chapters 2
> & 3 of the White Book, “Statistical Models in S”. Unfortunately, I do not
> have ready access to a major research library and I have way, way outspent
> my book budget. Someday I’ll probably buy a copy, but for the time being, I
> am stuck without it. So it would be great to have a piece of code that uses
> them explained in detail.
Not sure that you have a valid idea of the cost of that particular investment... at bookfinder.com
Bookseller Notes Price
1.
United States Softcover, ISBN 0412053012
Publisher: Chapman & Hall/CRC, 1991
Section: Computer Languages: The Attic
$21.94
Chapter 2 was useful for some of the the purposes you propose, but chapter 3 did not.
However, I would suggest that you might instead purchase "S Programming" by Venables and Ripley. And ... it was even cheaper at Bookfinder. Reviewing the indices shows of both texts shows a far greater treatment of the functions you list above. I found the later, more up-to-date text "Software for Data Analysis" to be less helpful in understanding the R/S "internals" than the "S Programming" text. It was surprisingly sparse with its coding examples. You could sometimes go for pages without seeing any code. Extended discussions of how the R/S approach differed from Java or C were not helpful to me. It would, however, be essential if you were headed toward S4 methods which seems to be it's main goal. And of course this is just one reader's (and a not particularly expert reader) experience.
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list