Not a direct answer to your question, but...
You might consider using the R.oo package, from H. Bengtsson. It's
very stable, written in pure R, and cleanly allows you to do
pass-by-reference OO programming, with no tricks.

HTH,
af

2009/6/23 Troy Robertson <troy.robert...@aad.gov.au>:
> Hi all,
>
>
>
> Prefix: I am a frustrated Java coder in R.
>
>
>
> I am coding a medium sized ecosystem modelling program in R.  I have changed 
> to using S4 objects and it has cost me an order of magnitude in execution 
> speed over the functional model.  I cannot afford this penalty and have found 
> that it is the result of all the passing-by-value of objects.
>
>
>
> I see that you can now safely inherit from environment in V2.9.0.
>
> That got me all excited that I would now be able to pass objects by reference.
>
>
>
> But...
>
> That doesn't seem to be the case.
>
> It only seem that passing an environment which holds the object allows for 
> pass-by-reference and that passing an object which inherits from environment 
> doesn't.
>
> Why is this the case, either an object inherits the properties of its parent 
> or it doesn't.
>
> Has anyone else had a play with this?  Or have I got it all wrong.
>
>
>
> I tried the below:
>
> -----------------------------------------------------------------------------------------
>
> setClass('foo', representation=representation(stuff='list', bar='numeric'),
>
>                     prototype=list(stuff=list(), bar=0),
>
>                     contains='.environment')
>
>
>
> setGeneric('doit', function(.Object, newfoo='environment') 
> standardGeneric('doit'))
>
>
>
> setMethod('doit', 'foo', function(.Object, newfoo){new...@bar <- 10})
>
>
>
> z <- new('foo')
>
>
>
> z...@stuff$x <- new('foo')
>
>
>
> doit(z,z...@stuff$x)
>
>
>
> z...@stuff$x@bar
>
>
>
> [1] 0
>
> ------------------------------------------------------------------------------------------
>
>
>
> Can anyone help with a better way of doing this.
>
> I'm trying to avoid all the indirection of packing and unpacking environments 
> for passing.
>
>
>
>
>
> Thanks heaps
>
>
>
> Troy
>
>
>
>
>
> Troy Robertson
>
> Database and Computing Support Provider
>
> Southern Ocean Ecosystems, ERM/Fish
>
> Australian Antarctic Division
>
> Channel Highway, Kingston 7050
>
> PH: 03 62323571
>
> troy.robert...@aad.gov.au
>
>
>
>
> ___________________________________________________________________________
>
>    Australian Antarctic Division - Commonwealth of Australia
> IMPORTANT: This transmission is intended for the addressee only. If you are 
> not the
> intended recipient, you are notified that use or dissemination of this 
> communication is
> strictly prohibited by Commonwealth law. If you have received this 
> transmission in error,
> please notify the sender immediately by e-mail or by telephoning +61 3 6232 
> 3209 and
> DELETE the message.
>        Visit our web site at http://www.antarctica.gov.au/
> ___________________________________________________________________________
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Antonio, Fabio Di Narzo
Ph.D. student at
Department of Statistical Sciences
University of Bologna, Italy

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to