Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread Steve Lianoglou
Hi, On Wed, Oct 14, 2009 at 4:23 PM, Martin Morgan wrote: > Steve Lianoglou wrote: >> Very clever, that looks to do the trick! > > I think though that all Square's then share the same environment > (created in the prototype) and hence area. > >> area(new("Square", length=50, width=100)) > Accessi

Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread hadley wickham
Just a note: this technique is called memoisation. Hadley On Wed, Oct 14, 2009 at 3:42 PM, Benilton Carvalho wrote: > Thank you very much, Martin. :) > > b > > On Oct 14, 2009, at 5:23 PM, Martin Morgan wrote: > >> Steve Lianoglou wrote: >>> >>> Very clever, that looks to do the trick! >> >> I th

Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread Benilton Carvalho
Thank you very much, Martin. :) b On Oct 14, 2009, at 5:23 PM, Martin Morgan wrote: Steve Lianoglou wrote: Very clever, that looks to do the trick! I think though that all Square's then share the same environment (created in the prototype) and hence area. area(new("Square", length=50, wid

Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread Martin Morgan
Steve Lianoglou wrote: > Very clever, that looks to do the trick! I think though that all Square's then share the same environment (created in the prototype) and hence area. > area(new("Square", length=50, width=100)) Accessing [1] 50 Which is quite efficient at doing the calculation, but maybe

Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread Steve Lianoglou
Very clever, that looks to do the trick! Thanks, -steve On Oct 14, 2009, at 2:57 PM, Benilton Carvalho wrote: If you change 'area' to an environment, you may be able to get something close to what you want. For example: setClass("Square", representation( len

Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread Benilton Carvalho
If you change 'area' to an environment, you may be able to get something close to what you want. For example: setClass("Square", representation( length='numeric', width='numeric', area='environment'

[R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread Steve Lianoglou
Hi, I was wondering if there was a way to store the results of a computationally expensive "getter" call on an S4 object, so that it is only calculated once for each object. Trivial example: let's say I want to cache the "expensive" area calculation of a square object. setClass("Square"