From ggrothendieck at gmail.com  Tue Aug 29 12:40:55 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Tue, 29 Aug 2006 06:40:55 -0400
Subject: [Rd] vector S4 classes
In-Reply-To: <AC7EC9F8-ECDC-4E6A-BB8D-7C53A4A7605F@soc.soton.ac.uk>
References: <AC7EC9F8-ECDC-4E6A-BB8D-7C53A4A7605F@soc.soton.ac.uk>
Message-ID: <971536df0608290340r39b99318sca33cf20a4ac1931@mail.gmail.com>

You might want to look at the source for the R 'its' package.  It defines
an S4 class for an irregular time series whose representation
consists of

1. a matrix portion analogous to your vector portion to hold the series
    of multivariate series, and
2. a "dates" slot analogous to your accurate slot

and defines numerous methods for this class.

On 8/29/06, Robin Hankin <r.hankin at noc.soton.ac.uk> wrote:
> In the Green Book, section 7.5 discusses new vector classes and uses
> quaternions
> as an example of a vector class that needs more than one number per
> element.
>
> I would like to define a new class that has a numeric vector and a
> logical
> vector of the same length that specifies whether the measurement was
> accurate.
>
> The following code does not behave as desired:
>
>  > setClass("thing",representation("vector",accurate="logical"))
> [1] "thing"
>  > dput(x <- new("thing",1:10,accurate=rep(T,10)))
> structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), accurate = c(TRUE,
> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), class =
> structure("thing", package = ".GlobalEnv"))
>  > x[1:3]
> [1] 1 2 3
>  > dput(x[1:3])
> c(1, 2, 3)
>  >
>
> because, although the "accurate" slot is filled as desired in "x",
> when extracting the first
> three elements, it seems to be lost.
>
> What is the appropriate setClass() call to do what I want?  Or indeed
> is making "thing"
> a vector class as sensible idea here?
>
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>




[Rd] vector S4 classes
Gabor Grothendieck