[R] pass by reference

Jan T Kim jttkim at googlemail.com
Tue Aug 14 11:07:41 CEST 2012


On Mon, Aug 13, 2012 at 11:20:26PM -0300, Alexandre Aguiar wrote:
> Sachinthaka Abeywardana <sachin.abeywardana at gmail.com> escreveu:
> >Think you are missing the point,
> 
> As lover of C-style pointers, I must admit that hiding complexities
> (and associated problems) of pointers is a great feature of all successful
> high level languages (HLLs). As much as they spare time and can be easily
> learned by non-programmers, they impose penalties in performance and
> memory consumption.
> 
> Most drawbacks of HLLs have been effectively and efficiently addressed
> by a number of strategies in such a way that currently we have a wide
> variety of options. Languages have become tools to solve problems and,
> as such, we must pick the proper tool for each problem. That means the
> very first step is properly assessing the problem.

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

> 
> My 2 cents.
> 
> 
> --
> 
> Alexandre Aguiar, MD SCT
> SPS Consultoria
> 
> -- 
> Sent from my tablet. Please, excuse my brevity.
> Enviado do tablet. Por favor, perdoe a brevidade.
> Publi?? de le tablet. S'il vous pla??t pardonnez la bri??vet??.
> Ver??ffentlicht aus dem Tablet. Bitte verzeihen Sie die K??rze.
> Enviado desde mi tablet. Por favor, disculpen mi brevedad.
> Inviato dal mio tablet. Per favore, scusate la mia brevit??.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: jttkim at gmail.com                                |
 |             WWW:   http://www.jtkim.dreamhosters.com/              |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*



More information about the R-help mailing list