What's the proposal here? To eliminate "double" as a class? No
objection from this corner. As I remember, it was put in early in the
implementation of methods, when I was confused about what R intended in
this area (well, I'm not totally unconfused even now).
If this is the proposal, we could implement it in r-devel and see if
there are complaints.
Prof Brian Ripley wrote:
> On Tue, 13 Nov 2007, Simon Urbanek wrote:
>
>
>> On Nov 13, 2007, at 3:36 AM, [EMAIL PROTECTED] wrote:
>>
>>
>>> Any idea why S4 doesn't allow slots of type "double"?
>>>
>>>
>> Type (as in storage type and "double" is a storage type) has nothing
>> to do with classes. You cannot create slots for types, only for classes.
>>
>
> Unfortunately not in the world of the 'methods' package (which seems to
> differ here from the Green Book and S-PLUS). There's a basic class
> "double" (and also "single") defined in BasicClasses.R. It say:
>
>
>> getClass("double")
>>
>
> No Slots, prototype of class "numeric"
>
> Extends: "vector", "numeric"
>
>
>> getClass("numeric")
>>
>
> No Slots, prototype of class "numeric"
>
> Extends: "vector"
>
> Known Subclasses: "double", "integer"
>
> So it is an otherwise unspecified subclass of "numeric".
>
> Now when you do
>
>
>> a <- new("numeric", pi)
>> a
>>
> [1] 3.141593
>
>> class(a)
>>
> [1] "numeric"
>
> you are in fact calling class() on a REALSXP, and that is set up to report
> "numeric" (the implicit class comes from mode not type, except for
> "integer").
>
> Anther area of confusion is that as.numeric, as.double and as.real are
> three names for the same thing, but is.numeric and is.double are not the
> same. So we end up with
>
>
>> x <- 1:3
>> is.numeric(x)
>>
> [1] TRUE
>
>> identical(x, as.numeric(x))
>>
> [1] FALSE
>
>> x <- pi
>> is.numeric(x)
>>
> [1] TRUE
>
>> identical(x, as.numeric(x))
>>
> [1] TRUE
>
> Basically I think class() is wrong (it should use "double"), but it was
> not my choice and it was presumably done to agree with the Green Book.
>
> I agree that it would be best to remove the "double" and "single" S4
> classes. At least in the version of S-PLUS I have left, "double" does not
> exist -- "single" does but is a distinct storage type.
>
>
>
>>
>>>> setClass("A", representation(a="double"))
>>>>
>>> Error in makePrototypeFromClassDef(properties, ClassDef, immediate,
>>> where) :
>>> in making the prototype for class "A" elements of the prototype
>>> failed to
>>> match the corresponding slot class: a (class ?double? )
>>>
>>> "numeric", "integer", "character", "complex", "raw", etc... they all
>>> work but "double" doesn't. Any reason for this strange exception?
>>>
>>>
>> AFAICS there is no way to create an object of the class "double" (save
>> for 'faking' it by creating an informal S3 object), so such definition
>> is useless. And given this fact, even the internal code is unable to
>> create it, so it doesn't match the signature. Note:
>>
>>
>>> a=new("double")
>>> class(a)
>>>
>> [1] "numeric"
>>
>>> is(a,"double")
>>>
>> [1] FALSE
>>
>> I think it comes from the fact that there is an S4 definition for the
>> class "double" which is not valid. That is probably a bug and the
>> class definition should be removed.
>>
>> Cheers,
>> Simon
>>
>> ______________________________________________
>> [email protected] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel