10 ms·
R, the master troll of statistical languages (2012)
- tocomment 14y agoSo why not just use Python these days?
- billwilliams 14y agoUse both and you'll see. Python can do modeling, can do exploratory work and is great in production. R is brilliant at exploratory work and modeling. Having a core in functional programming helps too.
- tocomment 14y agoActually I just finished my first week working in R. And I could have done the same amount of work in Python in an hour :-( It's like every line I wrote there was some catch or trick I had to know just to get it to work. Pretty frustrating.
- vsbuffalo 14y agoThat's just part of learning programming languages. Learn a language well, then decide. I thought Python was better than R, but a homoiconic functional language just makes sense for statistics. You get really neat functions like with, within, local, that let you keep everything tidy. S3/4 classes are hugely inspired by CLOS. It's also a great language for extending C with.
- houshuang 14y agoI've just been learning R for my grad studies (and general data exploration), and was really torn between R and Python, especially with IPython Notebook, pandas etc. I came from a Ruby background so both would be newish to me. What made me start with R (although I'm still following IPython dev, and will probably end up switching eventually) is the massive amount of material available to learn stats etc with R. I've seriously got something like a 100 textbooks on R on my system, intro to stats with R, machine learning with R, questionnaire analysis with R, bayesian stats with R... There are Coursera classes, the amazing r-bloggers.com, etc. For someone who is simultaneously learning statistics and a tool, this is invaluable. For Python, there's still very little. There's Wes' book, which is mostly about pandas and a lot of finance/time series stuff... I haven't seen a single "intro to stats in social sciences with Python"... There must be one book out there that is open source, which could just be rewritten with Python examples? (The most useful thing I've seen is people reworking examples from Machine Learning for Hackers, or one of the Coursera R courses, in Python).
- phren0logy 14y agoThere is one basic stats book using Python: http://greenteapress.com/thinkstats/ http://greenteapress.com/thinkstats/
- rm999 14y agoAs the article discusses, R has a steep learning curve. Mastering R requires knowing dozens of commands and tricks, but once you learn those the language becomes very expressive and quick to work with. I agree it's frustrating. I've been working with R on and off for more than five years and almost exclusively for 1-2 years, and I still need google every ten minutes to remember some esoteric command that is perfect for the problem at hand. In my experience this is still quicker and less error-prone than python, which often requires you to effectively roll out your own solutions for small data processing needs.
- trts 14y agoI'm about where you are at. I struggled with doing things in R for a year or so, while I was initially using it to do some cool graphics that I couldn't elsewhere, following mostly by example. After spending enough time using it, things began to "click" for me, and now I prefer to do most of my work in R. I still struggle sometimes to write nice looking code in R, but I've known people who are pretty good at managing it. If you have to inherit an R program from someone else though, it's almost guaranteed to be a nightmare to comprehend.
- rm999 14y agoAt this point, mostly library support. Python is quickly getting closer to being a viable R replacement, but it's simply not there yet IMO. The two biggest holes in python for me are: * The lack of built-in dataframes and libraries to work on them (like plyr). Pandas seems to be getting pretty good, but it's still not as mature as R's solutions. * Visualization. ggplot for R is great, matplotlib for python not so good IMO. I've heard Bokeh and rplot are attempting to bring ggplot functionality to python. Again, not nearly as mature as R's solution. I'd love to move to Python because R is not a fun language to develop software in. But at this point, R is by far the better tool for working with data (for my needs at least).
- elyase 14y agoAny specific example on what pandas is lacking in comparison to R packages?
- hadley 14y agoI'd love to hear what makes R not-fun to develop in. I'm always on the look-out for common pain points.
- rm999 14y agoA large pain point for me is remembering the huge number of useful commands in R - I use at least 5-10x as many keywords in R as I did in C++. As I mention in another comment I basically need a reference (usually google and ?) at all times to keep track of these commands and their parameters. In many ways it's great that all these functions exist because I can analyze datasets an order of magnitude more quickly (in development time) than I could in a more traditional language, but developing in R is far more stressful to me. When I'm writing production-level code I constantly have to worry about readability and whether someone else who is reading my code will intuitively understand what I'm doing. With so many commands and so many ways to do things this can be challenging. I find my R code is often lower 'quality' than what I write in something like Python or C. There are many little idiosyncrasies in R's syntax, I feel like I never grokked the language. For example, pretty much anytime I see '~' I have to relearn what is going on. From a mathematical perspective I appreciate that vectors are indexed from 1 instead of 0, but from a programming perspective it can be annoying. BTW, thanks for contributing so many great things to R, I owe a lot of what I do to you.
- minimaxir 14y agoI don't know how Python handles it, but R uses vector operations for almost every function, meaning that for large data sets (10000+), the efficiency of data manipulation in R is always O(1), and may otherwise be O(n) in Python. I have a function in R that given a list of keywords, for each word (~100 keywords), it checks a data frame that stores a list of keywords (~5000 lists of keywords, ~10 keywords/list) to see which keywords matches the keywords in each row of the data frame. Efficiency using straight for loops would be O(mno) and could take awhile. But in R, all those operations are vectors, and it takes less than a second.
- teraflop 14y ago"Vector operations" cannot magically turn an O(n) operation into an O(1) operation, no matter what language you're using.
- minimaxir 14y agoFair enough. You're right, O(1) might not be the most accurate efficiency for what I'm describing.
- pyoung 14y agoI imagine your mileage may vary depending on the functions and operations that you are performing. I did a simple test of python vs R and python was the overwhelmingly faster. I believe both languages are primarily written in C, and as such, the speed of your program will depend on the 'efficiency' of the underlying code for the functions you are using.
- cschmidt 14y agoR is horrifically slow on loops. If you can vectorize the operation, then it will be reasonably fast. If you have to use an explicit loop, then python will be faster. My previous company had a saying that "R is fast if your write it in C". If you have many nested loops, you'll probably need to write a C extension.
- guylhem 14y agoThis is the very same critic that was (and still is) made about perl. >> I won’t bother to explain all of these; the point is that, as you can see, they all return the same result (namely, the first column of the ice.cream data frame, named ‘flavor’). Having many ways to do one thing is good - whatever float your boat you know. Just for the given examples, I see how one may be better in a loop (the one where you use 1) while another one may be better when you type it on the command line to check stuff (the one with flavour) >> The answer is that when you’re trying to learn a new programming language, you typically do it in large part by reading other people’s code– No. You learn by doing. You write some stuff, test it, and if you don't get the result you expect go back to try and figure out what's wrong. And even before doing that, you set aside some time to LEARN about the language. But maybe, just maybe, the problem is not with the tool but with the person using it? >> I have to confess that I’ve never set aside much time to really learn it very well; what basic competence I’ve developed has been acquired almost entirely by reading the inline help and consulting the Oracle of Bacon Google when I run into problems. I’m not very good at setting aside time for reading articles or books or working my way through other people’s code (probably the best way to learn), so the net result is that I don’t know R nearly as well as I should. At least that's honest. Maybe you don't do well with a language (any language!) because huh, you didn't take time to study it and expect it to magically work?? I know I'm no good in java, but I also know why - I never took some time to actually learn it. I can do things with java, but not very complex things, and when I fight my way out of a problem I caused, I won't blame java but myself and my lack of knowledge of java.
- pekk 14y agoR has great capabilities. But it is not great for encouraging readability. For learners, it tends to feel confusing and lawless. It requires an investment. This is a significant fact about R. It is not equally true of all languages. It isn't ideal, either. We can do better. But for years there was nothing comparable in open source (perhaps even outside open source). That is also true of Perl.
- Cowen 14y ago> This is the very same critic that was (and still is) made about perl. It's funny how similar the arguments are. They can both be described as a language with some serious gotchas, but that's simple enough and has such a great package collection that it's easy to get a lot of things done very quickly. That description could also fit Javascript.
- jimmar 14y agoI think R's biggest strength of R is the package ecosystem. I would not trade the large community of active package developers for slightly friendlier syntax.
- carterschonwald 14y agoIndeed, the ecosystem of actively deved numerical libs is the only upside to R over other tools. It's a pretty large cliff for any other tool chain to climb over. --someone who's writing numeric/ data analysis tools in Haskell.
- pilgrim689 14y agoOff-topic but: Can you comment on the significance of this cliff for a team considering moving from R to Haskell for data analysis? Is the availability for statistics packages really sparse in Haskell?
- carterschonwald 14y agothe answer is: it depends! Shoot me an email at Wellposed and I can try to better answer your question. I am quite literally building a full data analysis stack (as a product) in haskell, some parts of which will be available as a sort of proprietary augmented version of the haskell platform, and some parts are / will be open source. I do think that there are compelling reasons to consider Haskell / GHC for analytical workloads, but depending on the details it really depends. The principal cliff is just the HUGE number of (mostly poorly designed) libraries for many standard analyses written in R. Theres some nice engineering approaches to circumvent this, and theres some really exciting libs that a uniquely awesome and handy in haskell land. A notable example is AD, a really easy to use auto differentiation lib by Edward Kmett, which has a really exciting refactor thats nearly done that will make it useable by mortal Haskellers :) http://hackage.haskell.org/package/ad http://hackage.haskell.org/package/ad and https://github.com/ekmett/ad https://github.com/ekmett/ad (I've some neat bits i'll be hopefully adding to AD myself in the next month)
- deleted 14y ago[deleted]
- Gravityloss 14y agoThe problem is that here the "generic" tools like "apply" are not really generic. Hence you can not use your intelligence and creativity to deduce a working program using a small toolset that you know fully. Instead you must use a huge number of special tools that do only a few things. The code is hard to read, hard to write, slow, the compiled version is big. It is also error prone since you must use a large number of different paradigms. Some might have their arguments slightly differently. It's produced by googling for everything (or if there's a decent builtin help system, using that). It seems strange that such concepts, like generic data types, operators and functions are not more widely spread. For example if you can calculate "max(a-b)" even if "a" is a matrix and "b" is a scalar, that's already quite nice. This can increase productivity a lot. Since such design models are so fundamental, they are rarely found in "matlab-like" extensions for other programming languages: instead you must constantly do type conversions and transformations by hand and use awkward middle man functions to access data types. Most of your code is housekeeping and little actual progress. See for example the problems with Julia where column and row vectors are totally different types: http://2pif.info/op/julia.html http://2pif.info/op/julia.html
- pygy_ 14y ago> See for example the problems with Julia where column and row vectors are totally different types: http://2pif.info/op/julia.html http://2pif.info/op/julia.html That was one year ago. They are still different types, but they behave as you would expect wrt arithmetics. julia> x = [1,2,3] 3-element Int64 Array: 1 2 3 julia> y = [1 2 3] 1x3 Int64 Array: 1 2 3 julia> y' 3x1 Int64 Array: 1 2 3 julia> x + y' 3x1 Int64 Array: 2 4 6 Their size and dimensions are still different, though, but it is mostly a concern for library writers. julia> ndims(x) 1 julia> ndims(y) 2 julia> ndims(y') 2 julia> size(x) (3,) julia> size(y) (1,3) See https://groups.google.com/forum/?fromgroups=#!msg/julia-dev/W2C9-HbXH3o/P8A8jo7FHSoJ https://groups.google.com/forum/?fromgroups=#!msg/julia-dev/... for the discussion that resulted from that post. Edit: I should add that there's now a mailing list dedicated to statistics with Julia: https://groups.google.com/forum/#!forum/julia-stats https://groups.google.com/forum/#!forum/julia-stats
- jamesjporter 14y agoThe metaphor I use to explain R is that most programming languages are like different varieties of swiss army knife: general tools that can do a lot of different stuff with relative ease. R, on the other hand, is like a fillet knife: its totally obtuse for most things, but in spite of its oddities it outshines all other choices at one specific task (statistical data analysis / filleting a fish respectively). Depending on what sort of camping trip you're going on you might want to bring one or the other or both.
- minimax 14y agoR has a rich heritage of trolling unsuspecting programmers coming from other languages. In ancient versions of R from the early 2000s, the underscore operator was synonymous for '<-', aka assignment. This is why in R some use periods for separators (ice.cream) rather than underscores (ice_cream), though just to make things more lulzy some package authors have started to use Java style camel case (iceCream) too. I saw an example of R code using underscore for assignment posted on twitter a couple of months ago. See if you can make heads or tails of this: http://www.stat.washington.edu/hoff/Code/hoff_raftery_handcock_2002_jasa/dist.r http://www.stat.washington.edu/hoff/Code/hoff_raftery_handco...
- pygy_ 14y ago> This is why in R some use periods for separators (ice.cream) rather than underscores (ice_cream) ... and since the dot is legal in identifiers, they use $ as lookup operator. > ice.cream$flavor [1] "chocolate" "vanilla" "butterscotch advocado surprise"
- rabz 14y ago> In ancient versions of R from the early 2000s, the underscore operator was synonymous for '<-', aka assignment. Huh, early Smalltalk mapped the left arrow to the underscore key; I'm not sure if Squeak and Pharo still do it, though.
- camus 14y agolet's stop using the word 'troll' at this point ok ? it's clearly an insult. doesnt make sense to call a language that way.
- mwexler 14y agoR is a great set of statistics wrapped in a crime of a programming language. You have to fight the latter to get to the former. Is the fight worth it? I and many others say yes... but it sucks that we even have to make that decision.
- dnc 14y agoWhen I think about R I find it difficult to stop making analogies between it and JavaScript. Both are dynamic, "script" languages with C-based syntax and with LISP-like nature that lurks underneath it. Both have functions as first class citizens. Both are inconsistent in different ways. Just to name a few that first come to my mind ... I think that these analogies reduced frustration that I had felt about R once when I "discovered" them and helped me to adopt and learn R.
- rck 14y agoThat makes sense - they were both inspired by Scheme (R is in many ways just a Lisp that uses M-expressions), but evolved to deal with immediate concerns that, in retrospect, have created difficulties as the years have gone by. It makes R and JavaScript great and frustrating at the same time.
- alexholehouse 14y agoLanguage issues asside, R is being propelled by an awesome group of developers (such as Hadley Wickham, Dirk Eddelbuettel, John Myles White, Brian Ripley etc). These people are why R is as successful as it has become - both through continued work on various aspects and packages and direct interaction with users new and old. Frankly, there should be some kind of slightly awkward parade for them all.
- cschmidt 14y agoI'd say that R is awesome, and that R is a fairly annoying language, all at the same time. (I'll go back to writing some R code now.)
- gmac 14y agoR has a million related built-in functions like sapply(), tapply(), lapply(), and vapply() Exactly that. I've always found R a horribly confusing mess, compared to general programming languages (I'm proficient in Ruby, JS, Obj-C). On the other hand, compared to some of the other commercial stats packages, it's beautiful and logical and reasonable. I regularly use Stata, where you're only allowed one data table in memory at once, and almost everything relies on side effects and Byzantine macros. E.g want to calculate a mean? First, 'summarise' the variable, then assign 'r(mean)' to a var name, then quote that the right way to be substituted into an expression where it's needed.
- WayneDB 14y agoThis was actually a fantastic introduction to an important aspect of R which I had only briefly explored in the past.