[R] setClass or setValidity?

Martin Morgan mtmorgan at fhcrc.org
Mon Mar 8 22:56:32 CET 2010


On 03/08/2010 07:18 AM, Albert-Jan Roskam wrote:
> Sorry: there was an error in the last sentence:
> And, inside those validity checks, is most of the checking done with 'if' 'else' computations, or is it also common to use try()?

For me it's a matter of taste, and usual to use if... (because you know
explicitly what you're trying to validate, whereas try() implies a kind
of 'something might go wrong...'). I find myself using setValidity() to
 separate out class definition from implementation.

Best,

Martin

> 
> Cheers!!
> Albert-Jan
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In the face of ambiguity, refuse the temptation to guess.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> --- On Mon, 3/8/10, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
> 
> 
> From: Albert-Jan Roskam <fomcl at yahoo.com>
> Subject: [R] setClass or setValidity?
> To: r-help at r-project.org
> Date: Monday, March 8, 2010, 4:14 PM
> 
> 
> Hi, 
>  
> I'm reading up on S4 classes *). There seem to be at least two ways of input validation:
> setClass() (using the 'validity' argument)  and setValidity(). Is it a matter of taste which function is used? Or should more complex validation code better be put in a setValiditity call?
> 
> *) A (Not So) Short Introduction to S4 Object Oriented Programming in R 
> V0.5.1 Christophe Genolini August 20, 2008
>  
> And, inside those validity checks, is most of the checking done with 'if' 'else' computations, or is it also common to use except()?
> 
> Cheers!!
> Albert-Jan
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In the face of ambiguity, refuse the temptation to guess.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
>       
>     [[alternative HTML version deleted]]
> 
> 
> -----Inline Attachment Follows-----
> 
> 
> ______________________________________________
> 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.
> 
> 
> 
>       
> 	[[alternative HTML version deleted]]
> 
> 
> 
> 
> ______________________________________________
> 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.


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

Location: Arnold Building M1 B861
Phone: (206) 667-2793



More information about the R-help mailing list