Re: [R] learning S4

2008-02-13 Thread Christophe Genolini
Robin Hankin a écrit :
 Christophe

 you might find the Brobdingnag package on CRAN helpful here.

Yep, I read it and I find it very usefull. A question anyway:

Is there a way to change a slot without using the - ?

Instead of
  new(obj)
  [EMAIL PROTECTED] - 3

I would like to have
  new(obj)
  setSlotA(obj,3)

In your vignette, 'Section 8 : Get and Set methods', you define 4 Gets, 
but no Set...

Christophe

__
R-help@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.


Re: [R] learning S4

2008-02-11 Thread Robin Hankin
Christophe

you might find the Brobdingnag package on CRAN helpful here.

I wrote the package partly to teach myself S4; it includes a
  vignette that builds the various S4 components from scratch,
in a step-by-step annotated cookbook.


HTH


rksh




On 8 Feb 2008, at 15:30, [EMAIL PROTECTED] wrote:

 Hi the list.

 I try to learn the S4 programming. I find the wiki and several doc.  
 But
 I still have few questions...

 1. To define 'representation', we can use two syntax :
- representation=list(temps = 'numeric',traj = 'matrix')
- representation(temps = 'numeric',traj = 'matrix')
   Is there any difference ?
 2. 'validityMethod' check the intialisation of a new object, but not
 the latter
   modifications. Is it possible to set up a validation that check  
 every
   modifications ?
 3. When we use setMethod('initialize',...) does the validityMethod
 become un-used ?
 4. Is it possible to set up several initialization processes ?   One
 that build an objet from a data.frame, one from a matrix...

 Thanks

 Christophe

 
 Ce message a ete envoye par IMP, grace a l'Universite Paris 10  
 Nanterre

 __
 R-help@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.

--
Robin Hankin
Uncertainty Analyst and Neutral Theorist,
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@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.


Re: [R] learning S4

2008-02-08 Thread Martin Morgan
Hi Christophe --

[EMAIL PROTECTED] writes:

 Hi the list.

 I try to learn the S4 programming. I find the wiki and several doc. But 
 I still have few questions...

 1. To define 'representation', we can use two syntax :
 - representation=list(temps = 'numeric',traj = 'matrix')
 - representation(temps = 'numeric',traj = 'matrix')
Is there any difference ?

See the help page for representation

 ?representation

for a description of the checks performed by this function.  View the
function definition for 'representation' with

 representation

to see the implementation details.

 2. 'validityMethod' check the intialisation of a new object, but not 
 the latter
modifications. Is it possible to set up a validation that check every
modifications ?

No. A solution is to create 'setters' that use slot- or @- and then
check validity explicitly; the 'user' would then invoke the setters
and avoid direct slot access.. 

 3. When we use setMethod('initialize',...) does the validityMethod 
 become un-used ?

'initialize' for signature .Object=ANY calls validObject sometimes
(when length(list(...))0; see

 getMethod(initialize, ANY)

for implementation details). So if your 'initialize' uses
callNextMethod (I think object oriented practice would encourage this)
and the appropriate conditions apply, then validity gets called. Some
'initialize' paradigms might not work very well with this setup, e.g.,

   .Object - callNextMethod() # validObject
   # further modify .Object and hence check validity again??

 4. Is it possible to set up several initialization processes ?   One 
 that build an objet from a data.frame, one from a matrix...

No, 'initialize' has only a single argument to dispatch on (.Object,
based on the prototype of the object being created) and so cannot be
specialized for additional arguments. Solutions include writing
conditional code within your 'initialize', or to create a new
'constructor' generic with it's own signature that performs initial
coercion before calling 'new'. Personally I think this is a good
solution, treating 'new' and 'initialize' as internal functions that
the 'user' does not invoke directly.

Hope that helps,

Martin

 Thanks

 Christophe

 
 Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

 __
 R-help@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.

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793

__
R-help@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.