[R] pass by reference

Bert Gunter gunter.berton at gene.com
Tue Aug 14 16:07:36 CEST 2012


(Offlist, as my comments are not worth bothering the list about).

I don't understand the purpose of this tirade (whose reasonableness I
make no judgment of). R is what it is. If you don't like it for
whatever reason, don't use it.

As a point of order, there are several packages that "automate" pass
by reference/pointers in R to some extent: packages ref, R.oo, and
proto are 3 that I know of, but I think there are others. My
understanding is that this tends to be computationally inefficient in
R, but I have no direct knowledge.

As you presumably already know, you can also implement this manually
through the use of environments and S3 or S4 semantics. You might also
be interested in Luke Tierney's comments on references in R:

http://homepage.stat.uiowa.edu/~luke/R/references.html

Cheers,
Bert

On Tue, Aug 14, 2012 at 2:07 AM, Jan T Kim <jttkim at googlemail.com> wrote:
> 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  >=-----*
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list