Re: [R] creating list with 200 identical objects

2009-06-02 Thread Rainer M Krug
On Tue, Jun 2, 2009 at 10:44 AM, Wacek Kusnierczyk wrote: > Rainer M Krug wrote: >> Thanks a lot Wacek for this clear description of the problem - I was >> not aware, that it is that complex. >> I definitely did not consider the initialize() function in writing my code. >> >> But as I only want to

Re: [R] creating list with 200 identical objects

2009-06-02 Thread Wacek Kusnierczyk
Rainer M Krug wrote: > Thanks a lot Wacek for this clear description of the problem - I was > not aware, that it is that complex. > I definitely did not consider the initialize() function in writing my code. > > But as I only want to allocate the space for the objects, it does not > matter here. Bu

Re: [R] creating list with 200 identical objects

2009-06-02 Thread Rainer M Krug
Thanks a lot Wacek for this clear description of the problem - I was not aware, that it is that complex. I definitely did not consider the initialize() function in writing my code. But as I only want to allocate the space for the objects, it does not matter here. But when I write a simulation and

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: > > consider: > > setClass('foo', >representation=representation(content='environment')) > setMethod('initialize', 'foo', function(.Object) { > .obj...@content = new.env() > .obj...@content$name = 'foo' > .Object }) > > foos = rep

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Wacek Kusnierczyk
Romain Francois wrote: > > rep( list( new("track") ), 5 ) > lapply( 1:5, function(x) new("track") ) > list( new("track") ) [ rep(1, 5 ) ] but note: these are not all equivalent. the second creates a list of five distinct objects, the first and last ones create a list of five times the same object

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Rainer M Krug
On Mon, Jun 1, 2009 at 12:27 PM, Chuck Cleland wrote: > On 6/1/2009 6:08 AM, Rainer M Krug wrote: >> Hi >> >> I am doing an simulation, and I a large proportion of the simulation >> time is taken up by memory allocations. >> >> I am creating an object, and storing it in a list of those objects. >>

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Rainer M Krug
On Mon, Jun 1, 2009 at 12:19 PM, Romain Francois wrote: > Hi, > > Here are a few ways: Thanks - I like it when I have a choice. > > rep( list( new("track") ), 5 ) OK - This one is executing new("track") once, and copying it into a list. > lapply( 1:5, function(x) new("track") ) This one execu

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Chuck Cleland
On 6/1/2009 6:08 AM, Rainer M Krug wrote: > Hi > > I am doing an simulation, and I a large proportion of the simulation > time is taken up by memory allocations. > > I am creating an object, and storing it in a list of those objects. > > essentially: > > x <- list() > for (t in 1:500) { > x[1]

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Romain Francois
Hi, Here are a few ways: rep( list( new("track") ), 5 ) lapply( 1:5, function(x) new("track") ) list( new("track") ) [ rep(1, 5 ) ] Romain Rainer M Krug wrote: Hi I am doing an simulation, and I a large proportion of the simulation time is taken up by memory allocations. I am creating an ob

[R] creating list with 200 identical objects

2009-06-01 Thread Rainer M Krug
Hi I am doing an simulation, and I a large proportion of the simulation time is taken up by memory allocations. I am creating an object, and storing it in a list of those objects. essentially: x <- list() for (t in 1:500) { x[1] <- new("track") } I would like to initialize in one go, to avoid