[R] "A critique of R and S-PLUS"

Duncan Murdoch murdoch at stats.uwo.ca
Thu Oct 30 13:38:05 CET 2008


On 10/30/2008 7:24 AM, Jan T. Kim wrote:
> On Thu, Oct 30, 2008 at 09:15:54AM +0100, Liviu Andronic wrote:
>> Dear all,
>> 
>> The other day I stumbled on this article, "A critique of R and S-PLUS"
>> [1], and got curious on whether the points outlined are (still) valid.
>> The article is quite old, dating 2004, but was updated several times.
>> 
>> Regards,
>> Liviu
>> [1] http://fluff.info/blog/arch/00000041.htm
> 
> It's basically true that R notionally passes parameters by value, i.e.
> functions cannot alter objects they're passed to them by their callers.
> 
> The critique that "this makes the language slow" is debatable, as the R's
> "pass by promise" mechanism avoids much unnecessary copying. Personally,
> I don't think that performance issues should be considered "first and
> foremost", as the decision whether to use references should primarily
> follow from the content i.e. the problem to be solved. There are
> plenty of problems which require references, so not having a pass by
> reference mechanism is a limitation.
> 
> In principle, it's possible to use environments in R for passing by
> reference. The practical use of this is limited by the fact that the
> majority of functions provided by standard packages don't operate on
> environments, though.

I don't think the last paragraph is a valid criticism.  The majority of 
functions provided by standard packages work on the pass by value 
semantics, so of course they can't handle environments being used to 
pass by reference.  But that doesn't stop you from writing your own 
functions that use pass by reference.  You just take the value out of 
the wrapper when you pass it to a pass-by-value function.

It's the same in C:  if p is a pointer to an integer, then you can't use 
p where you want an integer, you need to use *p, to dereference the 
pointer.  There are other languages like Pascal where the compiler 
handles this implicitly, and I think they end up with nicer syntax than 
C, but they don't really remove any practical limitations on the scheme.

That said, I don't think the "wrap it in an environment" way of making 
reference objects is ideal; environments do so many other things besides 
acting as references that it makes code unclear.

Duncan Murdoch



More information about the R-help mailing list