4 ms·
R is a pretty terrible language for many reasons, and it always surprises me when it rises to the top on HN. But in terms of code quality within R itself, I wa
by rgovostes 15y ago
R is a pretty terrible language for many reasons, and it always surprises me when it rises to the top on HN.
But in terms of code quality within R itself, I was surprised to find that a number of its .c files are actually machine-translated Fortran, so I'm guessing the author's statistics are not far off.
I discovered this when I decided to confirm my suspicions that my (the?) most frequently used function, t(), which computes the transpose of the matrix, was implemented about as naively as possible. If R developers were really concerned with speed, this is probably the first place to start optimizing.
- gfodor 15y agoCan you go into more detail? I've been toying with learning R for ad-hoc analysis but if there is a better alternative worth learning I'd love to hear about it.
- dagw 15y agoDepends on what you mean by "better". MATLAB and python+numpy will almost certainly run faster than R in almost all situations, they are also far more pleasant to program in (in my opinion). However R has the advantage that it will have support for every obscure statistical analysis routine you can ever think of. It also has better support for reading in data from all kinds of sources and handling things like missing and invalid data. So if your goal is to quickly read in a bunch of data sets (that are small enough that performance isn't a critical issue) from arbitrary sources, run a bunch of statistical functions on that data and turn those results into pretty graphs, then R is pretty great.
- onan_barbarian 15y agoCorrect. The language R is just plain weird (insane ideas about scoping/binding that seem to be completely unlike anything you've seen in any reasonably designed language in the last 20 years) and not very efficient to boot, unless you hit one of the bits that's just C under the hood. However, the vast, vast repository of every statistical analysis under the sun - not just 'core R' but every thing that any statistician has hacked up - is unparalleled. My 'coping with R' strategy is to do all the heavy lifting data manipulation in C/C++/Python, then do one-shot things in R. I just pass csv files around but there are tighter integrations of R and python if you want to look into that.
- dagw 15y agoJust as an aside, "coping with R" would be an awesome concept for a book or series of blog posts.
- onan_barbarian 15y agoOr maybe 'Living with R', sort of akin to the self-help-book 'Living with Chronic Fatigue Syndrome' type genre.
- etrain 15y agoCould you go into more detail about the "insane" scoping/binding ideas? I've always found the environment model very straightforward and am wondering if I'm missing something.
- jamesbkel 15y agoWhat you describe is typically how I use R. It certainly has it limits performance wise, but it is hard to beat as a "stat toolbox". Even in cases where it wasn't up to performance needs, I've found it useful for investigating which methods to use prior to implementing a full-blown solution. For example, I used the free R package "earth" to confirm that something like MARS(Multivariate Adaptive Regression Splines) is a good approach to a particular analysis. For my client that initial test justified paying Salford Systems for their great, but expensive, CART/MARS software.