Skip to content
Prev 303308 / 398506 Next

pass by reference

On Mon, Aug 13, 2012 at 11:20:26PM -0300, Alexandre Aguiar wrote:
yes, I quite agree. In my experience, the root of the trouble leading
to "how can I pass things by reference in R" requests is that many problems
involve objects that retain their identity while their attributes change in
a dynamic way. These are represented more adequately by having multiple
functions changing state of the same (identical!) object, rather than
approximating this by repeatedly replacing an object with an updated
copy of itself, or by using other "hacks".

The overheads / inefficiencies that come with such hacks are really just
a consequence of an inadequate representation of the problem (i.e. "as
though one had not assessed it properly", if you will). As a further
indication that this is a design issue rather than one of optimisation
at the implementation level, notice that from a database perspective,
holding multiple copies that represent the same thing in memory amounts
to a denormalised design.

Personally, I understand functional programming evangelists who object
to state and side effects because this "purism" is adequate (and also
often very elegant) for enabling parallel and distributed computing. But
noticing that this is not much of an issue for R (which e.g. doesn't
support multithreading much), I do think on a regular basis that
providing a mechanism enabling multiple references to one instance
would be an improvement that would not do too much damage.

As it is, I've resigned to using other languages where I need an object
graph, and producing a first normal form type of table where I want to
do something in R. But I do get the feeling that I'm doing something
not quite right, and I frequently reiterate the problem analysis outlined
above to myself in order to put that funny feeling behind me.

Just my 2 pence, Jan