Live data from Hacker News

The R language, for programmers

johndcook.com

11–20 of 79 posts

Re: The R language, for programmers

#11
To my mind some of R's plusses are data frames and the ability to indicate missing values in vectors of any type. Some of the weird stuff is the lazy evaluation of arguments, the ability to know the names of variables bound to function arguments, and the ability to snoop up the environment stack. Some distinct minuses are the changing of types (dropping of dimensions on select), semi-reserved terms, and c()'s squashing of complex types. One of my articles on the topic: Survive R http://www.win-vector.com/blog/2009/09/survive-r/ .

Re: The R language, for programmers

#12

Earlier quoted context omitted.

Are you familiar with Hadley's Advanced-R book? You can buy a hardcopy, but it's free online: http://adv-r.had.co.nz There's a section on lexical scoping, and lots of other non-basic stuff that is hard to find covered elsewhere at all, much less well. From what I've seen, this is absolutely the best reference for deep R stuff that exists.

I've seen it but haven't read in depth. Now that I see the scoping section I'll have to read through it.

Now that it's in print I suspect updates are less frequent, but until a few months ago sections were being added and rewritten pretty frequently, so it might have things now that it didn't when you looked last

Re: The R language, for programmers

#13
post #8

R is one of those languages that looks like it was designed in a vacuum by a very smart person. It has many common, modern PL constructs, but they're expressed syntactically in a way that in no way resembles any other language I've seen. The entire syntactic legacy of Algol, Pascal, C, etc, all are thrown by the wayside. Familiarity with any of those syntaxes felt to me like more of a liability than a help. That's no…

I agree, and I think that's exactly why an article like this exists. The R learning curve seems to be much gentler on people without too much serious programming experience in another language.

Have you looked at Julia at all? I'm only mildly familiar, but it looks super promising and I'm curious if the syntax there seems more normal or predictable for an experienced dev.

Re: The R language, for programmers

#15

I'd like to see a detailed explanation of R's scoping. It's not just lexical scoping; callees can deliberately manipulate the scope their arguments are evaluated in, for example. So you can call a function and pass arguments that are available in local scope, but the arguments are lazily evaluated, and the callee might evaluate them in an entirely different scope. Typically this is done for manipulating datasets. You…

You can think of the lazily evaluated arguments feature a lot like lisp macros. Basically, any function in R can either get the value of its arguments (i.e. acting like a regular function) or it can get the unevaluated expression passed for that argument (i.e. acting like a lisp macro). So in your "do.stuff" example, it's not a matter of special scoping, per se. The do.stuff function is actually getting the symbols "Width" and "Height" and then choosing to evaluate them with the value of the data argument as the innermost scope.

Re: The R language, for programmers

#16
post #8

R is one of those languages that looks like it was designed in a vacuum by a very smart person. It has many common, modern PL constructs, but they're expressed syntactically in a way that in no way resembles any other language I've seen. The entire syntactic legacy of Algol, Pascal, C, etc, all are thrown by the wayside. Familiarity with any of those syntaxes felt to me like more of a liability than a help. That's no…

I agree, and I think that's exactly why an article like this exists. The R learning curve seems to be much gentler on people without too much serious programming experience in another language. Have you looked at Julia at all? I'm only mildly familiar, but it looks super promising and I'm curious if the syntax there seems more normal or predictable for an experienced dev.

Yeah, I should have mentioned that - R for Programmers is exactly the kind of thing I'd need, even if it's not useful for my friends and family (largely scientists rather than programmers for whom the legacy of programming language syntax is completely unknown).

Julia looks cool; I think the syntax is meant to look familiar to people who've used Matlab or Octave extensively. I don't do tons of scientific computing, but Julia is on my list of tools to learn.

Re: The R language, for programmers

#17
I find R to be a great language for exploring a data set and doing some prototyping. There are a lot of wonderful statistical tools available through the core packages and even more through the various community extensions. It does have some significant issues that I've found limit the usefulness outside of prototyping

- pass by value only means code tends to end up as monolithic functions

- very slow in loops so lot contorting to move things to matrix operations

- they just last year got a version out that starts support for vectors and matrices with > 2^31 -1 elements which limits larger data applications.

I find the plotting with ggplot and statistical functionality to be second to none though.

Re: The R language, for programmers

#19
I'm curious for others thoughts on what to use for complex statistics if you needed high performance/speed.

Running an R script on a server to process data isn't efficient, but does that mean you have to roll your own stats package if you want to have a Java (for example) back-end?

Re: The R language, for programmers

#20

I find R to be a great language for exploring a data set and doing some prototyping. There are a lot of wonderful statistical tools available through the core packages and even more through the various community extensions. It does have some significant issues that I've found limit the usefulness outside of prototyping - pass by value only means code tends to end up as monolithic functions - very slow in loops so lot…

> pass by value only means code tends to end up as monolithic functions

I've actually found R works very well as a functional language with very lean functions. It's perhaps worth noting that R doesn't copy a dataframe in a function call if you don't modify it, which is a very common use-case for me. (I'm not sure if this extends to other datatypes)

> very slow in loops so lot contorting to move things to matrix operations

This is a fair criticism, I think more modern languages like Julia will win out here. That said, R has huge library support, I've often found there are compiled versions for a lot of what I want to do.

> they just last year got a version out that starts support for vectors and matrices with > 2^31 -1 elements which limits larger data applications

Again, a fair criticism. I've never considered R a "big data" tool, my workflow is usually a funnel where each step involves reducing data size by 1-3 orders of magnitude. For example, I may have 1 PB of transactional data, aggregate it in Hadoop to 20 TB of daily aggregated data, run a query that filters and aggregates it further, and then run my analysis in R on final data. In the end I may end up with 20 GB of data, which R can very easily handle.

Post reply on HN