hipsteR: re-educating people who learned R before it was cool

This morning, I started a tutorial for folks whose knowledge of R is (like mine) stuck in 2001.

Yesterday I started reading the Rcpp book, and on page 4 there’s an example using the R function replicate, which (a) I’d never heard before, and (b) is super useful.

I mean, I often write code like this, for a bootstrap:

x <- rnorm(2500)
sapply(1:1000, function(a) quantile(sample(x, replace=TRUE), c(0.025, 0.975)))

But I could just be writing

x <- rnorm(100)
replicate(1000, quantile(sample(x, replace=TRUE), c(0.025, 0.975)))

“Oh, replicate must be some new function.” Yeah, new in R version 1.8, in 2003!

I’m in serious need of some re-education (e.g., I should be using more of Hadley Wickham’s packages). Hence the beginnings of a tutorial.


Note: the title was suggested by Thomas Lumley. No connection to @hspter; it’s not really so hip. I probably should have written “geeksteR.”

About these ads

Tags: ,

7 Responses to “hipsteR: re-educating people who learned R before it was cool”

  1. Wei Zou Says:

    I used both and am not sure why replicate is better.

  2. Robert Young Says:

    Given that, as of a few seconds ago, there are more than 6,300 packages twixt CRAN and Bioconductor, it would be a full time job just to know the names of them, much less what they do. If there ever were a case of “there’s more than one way to do it”, R is the archetype.

    • Karl Broman Says:

      Good point.

      • Steve Says:

        Actually I think Perl beat R to the punch as it currently has 133,389 modules on CPAN, though it’s been around longer. Whether having lots of packages is a problem is in the eyes of the beholder though as former Perl addict I got very tired of some one reading my code only to say, “you know there is a module on CPAN that does the same thing”. While I would never complain about free software that is good, I find it somewhat unnecessary to replace working code with a package under the default assumption that it is somehow “better” or “faster”. If it is, and I need that capability, then I’ll happily include it. But sometimes it winds up being a “keep up with the Jones” kind of thing.

  3. Ben Bolker Says:

    I dislike replicate because it has a flexible (=confusing) set of “simplify” options. I like plyr::r*ply for these purposes (you get to define the return structure, and you get a progress bar thrown in !)

  4. Alex Blue Says:

    Re hipsteR. For programming, particularly multiple languages, you might want to include eclipse and the excellent statet (http://www.walware.de/goto/statet) plugin for R. It’s been around for many years and provides an excellent modelling, package development and general R project environment. You can check/build/debug code/packages straight from there, sweave and knitr, manage git/svn and much more.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 87 other followers