Re: [Rd] S4 objects in formulas (really, model frames)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 24 Jul 2012 06:15:38 +0100

The help for model.frame says

      Only variables whose type is raw, logical, integer, real, complex
      or character can be included in a model frame: this includes
      classed variables such as factors (whose underlying type is
      integer), but excludes lists.

Some S4 objects are of one of those types, but some are not. Some matrices are, some are not. Objects of class "Surv" are.

On 23/07/2012 21:33, David L Lorenz wrote:
> Hi,
> I have very carefully developed several S4 classes that describe
> censored water-quality data. I have routines for them that will support
> their use in data.frames and so forth. I have run into a problem when I
> try to use the S4 class as the response variable in a formula and try to
> extract the model frame. I get an error like:
>
> Error in model.frame.default(as.lcens(Y) ~ X) : object is not a matrix
>
> In this case, as.lcens works much like the Surv function in the survival
> package except that the object is an S4 class and not a matrix of class
> Surv. I would have expected that the model.frame function would have been
> able to manipulate any kind of object that can be subsetted and put into a
> data.frame. But that appears not to be the case. I'm using R 2.14.1 if
> that matters.
> I can supply the routines for the lcens data if needed.
> Am I looking at needing to write a wrapper to convert all of my S4
> classes into matrices and then extract the necessary data in the matrices
> according to rules for the particular kind of S4 class? Or, am I missing a
> key piece on how model.frame works?
> Thanks.
> Dave
>
> [[alternative HTML version deleted]]

The posting guide asked you not to do that. And to do your own homework.

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 24 Jul 2012 - 05:18:57 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 Jul 2012 - 07:00:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive