Re: [Rd] S4 classes and methods with optional arguments

2006-02-14 Thread Seth Falcon
On 14 Feb 2006, [EMAIL PROTECTED] wrote: > It seems to me like the generic should (always?) just have arguments > used for dispatch -- stream, in this case -- and that methods then > specify default values. There are advantages to adding named arguments to a generic to define the expected interf

Re: [Rd] S4 classes and methods with optional arguments

2006-02-14 Thread Martin Morgan
Echoing similar suggestions, but with a bit of philosophy... How about: setGeneric("rstream.sample", function( stream, ... ) standardGeneric("rstream.sample")) setMethod("rstream.sample", c( "numeric" ), function( stream, n = 1, ... ) { code } ) It seems to me like the gene

Re: [Rd] S4 classes and methods with optional arguments

2006-02-14 Thread Prof Brian Ripley
The problem is not the optional argument, but the attempt to dispatch on an argument not in the generic. setGeneric("rstream.sample", function(stream, ...) standardGeneric("rstream.sample")) setMethod("rstream.sample", "rstream", function(stream,n=1) { print(n) } ) rstream.sample(rs,

Re: [Rd] S4 classes and methods with optional arguments

2006-02-14 Thread Seth Falcon
Hi Josef, On 14 Feb 2006, [EMAIL PROTECTED] wrote: > I have used a construct to allow optional arguments: > > if(!isGeneric("rstream.sample")) setGeneric("rstream.sample", > function(stream,...) standardGeneric("rstream.sample")) First, a question: Is this idiom of testing for the generic befor

[Rd] S4 classes and methods with optional arguments

2006-02-14 Thread Josef Leydold
Hi, i have used S4 classes to implement a unified access to random number generators (package rstream on CRAN). I have used a construct to allow optional arguments: if(!isGeneric("rstream.sample")) setGeneric("rstream.sample", function(stream,...) standardGeneric("rstream.sample")) set