On Tue, 7 Mar 2006, hadley wickham wrote:
I tend to have to use trial and error myself. Here is another
possibility.
That's got the subsetting solved, so here's the next challenge
lm(x ~ y, z)
Error in as.data.frame.default(data) : cannot coerce class myobj
into a data.frame
I'm guessing this is pretty much impossible to get around, because
there is no way to tell eval how to deal with myobj type objects, and
lm only dispatches based on the type of the first argument.
Did you write an as.data.frame method? From ?model.frame
My as.data.frame is :
Can you create a small self contained reproducible example
that does not work? The reproducible example I provided earlier on
this thread worked fine.
One idea is to check what the class is of the output of
your .GGobiCall. If it were of class ggobiDataset then
it would in turn be calling
Can you create a small self contained reproducible example
that does not work? The reproducible example I provided earlier on
this thread worked fine.
I wish I could, and I'm very grateful for the help, but because the
data is an external pointer it's not easy to make a self-contained
example.
I think the problem is that your ggobiDataset objects are also
data.frame objects. They must NOT be. For example,
note how the following example fails once we add data.frame
to the class vector of x: The reason is that ordinary inheritance
is not used by model.frame; rather, it uses
[.ggobiDataset - function(x, ..., drop=FALSE) {
x - as.data.frame(x)
NextMethod([, x)
}
[[.ggobiDataset - function(x, ..., drop=FALSE) {
x - as.data.frame(x)
NextMethod([[, x)
}
$.ggobiDataset - function(x, ..., drop=FALSE) {
x - as.data.frame(x)
If your class is a subclass of data.frame then I think
it ought to be a special sort of data frame so all you
need to do is the following in which case you get subscripting
for free by inheritance:
# constructor
myobj - function(...)
structure(data.frame(...), class = c(myobj,
If your class is a subclass of data.frame then I think
it ought to be a special sort of data frame so all you
need to do is the following in which case you get subscripting
for free by inheritance:
My class is actually an external pointer to a data set stored in
ggobi, so I don't think this
Hi.
On 3/7/06, hadley wickham [EMAIL PROTECTED] wrote:
[.ggobiDataset - function(x, ..., drop=FALSE) {
x - as.data.frame(x)
NextMethod([, x)
}
[[.ggobiDataset - function(x, ..., drop=FALSE) {
x - as.data.frame(x)
NextMethod([[, x)
}
$.ggobiDataset -
x$total_bill
Error in $.default(x, total_bill) : invalid subscript type
where/how is $.default() defined? I don't have one;
getAnywhere($.default)
no object named '$.default' was found
Neither do I. I guess there is some internal magic going on for $.
Hadley
Just to get something reproducible lets assume the
objects of class myobj each consists of a one-element
list that contains a data frame. Then try this:
# constructor
myobj - function(...)
structure(list(value = data.frame(...)), class = myobj)
$.myobj - function(obj, x) .subset2(obj,
Just to get something reproducible lets assume the
objects of class myobj each consists of a one-element
list that contains a data frame. Then try this:
Thanks for that - it makes sense. Every time I try to use inheritance
in R, I always seem to end up using a different method.
Hadley
On 3/7/06, hadley wickham [EMAIL PROTECTED] wrote:
Just to get something reproducible lets assume the
objects of class myobj each consists of a one-element
list that contains a data frame. Then try this:
Thanks for that - it makes sense. Every time I try to use inheritance
in R, I
I tend to have to use trial and error myself. Here is another
possibility.
That's got the subsetting solved, so here's the next challenge
lm(x ~ y, z)
Error in as.data.frame.default(data) : cannot coerce class myobj
into a data.frame
as.data.frame.myobj - function(x) x[[1]]
lm(x ~ y, z)
The problem is that x[[1]] in the definition of as.data.frame.myobj
invokes [[.myobj whereas we want to extract the first element of the
list in the internal representation of x -- which is not the same.
Try this instead:
as.data.frame.myobj - function(x) .subset2(x, 1)
lm(y ~ x, z)
Call:
15 matches
Mail list logo