[R] classes with chron slots

2005-06-22 Thread Sebastian Luque
I'd like to define a class with a chron slot, but:

R> require(chron)
R> setClass("myclass", representation(datetime = "chron"))
[1] "myclass"
Warning message:
undefined slot classes in definition of "myclass": datetime(class "chron")
in: .completeClassSlots(ClassDef, where)

How should such a class be defined?

Sebastian
-- 
Sebastian P. Luque

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Martin Maechler
> "Sebastian" == Sebastian Luque <[EMAIL PROTECTED]>
> on Wed, 22 Jun 2005 15:50:50 -0500 writes:

Sebastian> I'd like to define a class with a chron slot, but:
R> require(chron)
R> setClass("myclass", representation(datetime = "chron"))
Sebastian> [1] "myclass"
Sebastian> Warning message:
Sebastian> undefined slot classes in definition of "myclass": 
datetime(class "chron")
Sebastian> in: .completeClassSlots(ClassDef, where)

Sebastian> How should such a class be defined?

You need to first make "chron" into a (pseudo-) S4 class, 
using  setOldClass()  

Then you can extend it or use it as slot class.

Martin Maechler, ETH Zurich

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Gabor Grothendieck
On 6/23/05, Martin Maechler <[EMAIL PROTECTED]> wrote:
> > "Sebastian" == Sebastian Luque <[EMAIL PROTECTED]>
> > on Wed, 22 Jun 2005 15:50:50 -0500 writes:
> 
>Sebastian> I'd like to define a class with a chron slot, but:
>R> require(chron)
>R> setClass("myclass", representation(datetime = "chron"))
>Sebastian> [1] "myclass"
>Sebastian> Warning message:
>Sebastian> undefined slot classes in definition of "myclass": 
> datetime(class "chron")
>Sebastian> in: .completeClassSlots(ClassDef, where)
> 
>Sebastian> How should such a class be defined?
> 
> You need to first make "chron" into a (pseudo-) S4 class,
> using  setOldClass()
> 
> Then you can extend it or use it as slot class.
> 

Also if you are referring to the chron package then 
the names of the chron classes are 'dates' and 'times' -- not 'chron'.

R> library(chron)
R> example(chron)
...snip...
R> class(dts)
[1] "dates" "times"

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Gabor Grothendieck
On 6/23/05, Martin Maechler <[EMAIL PROTECTED]> wrote:
> > "Sebastian" == Sebastian Luque <[EMAIL PROTECTED]>
> > on Wed, 22 Jun 2005 15:50:50 -0500 writes:
> 
>Sebastian> I'd like to define a class with a chron slot, but:
>R> require(chron)
>R> setClass("myclass", representation(datetime = "chron"))
>Sebastian> [1] "myclass"
>Sebastian> Warning message:
>Sebastian> undefined slot classes in definition of "myclass": 
> datetime(class "chron")
>Sebastian> in: .completeClassSlots(ClassDef, where)
> 
>Sebastian> How should such a class be defined?
> 
> You need to first make "chron" into a (pseudo-) S4 class,
> using  setOldClass()
> 
> Then you can extend it or use it as slot class.
> 


Also if you are referring to the chron package then 
the names of the chron classes are 'dates' and 'times' -- not 'chron'.

R> library(chron)
R> example(chron)
...snip...
R> class(dts)
[1] "dates" "times"

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Sebastian Luque
Thanks a lot Martin and Gabor!


On Thu, 23 Jun 2005 08:20:44 -0400,
Gabor Grothendieck <[EMAIL PROTECTED]> wrote:

[...]

> Also if you are referring to the chron package then 
> the names of the chron classes are 'dates' and 'times' -- not 'chron'.

However, when the object has both dates and times, then the class becomes
'chron', inheriting both 'dates' and 'times':

R> class(x)
[1] "chron" "dates" "times"

in the same example.

Cheers,
Sebastian
-- 
Sebastian P. Luque

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Gabor Grothendieck
On 6/23/05, Sebastian Luque <[EMAIL PROTECTED]> wrote:
> Thanks a lot Martin and Gabor!
> 
> 
> On Thu, 23 Jun 2005 08:20:44 -0400,
> Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> 
> [...]
> 
> > Also if you are referring to the chron package then
> > the names of the chron classes are 'dates' and 'times' -- not 'chron'.
> 
> However, when the object has both dates and times, then the class becomes
> 'chron', inheriting both 'dates' and 'times':
> 
> R> class(x)
> [1] "chron" "dates" "times"


Did you try the example I posted?  Its self contained and reproducible and 
it inherits from both "dates" and "times" yet there is no "chron" in the class 
vector, at least in that case.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Gabor Grothendieck
On 6/23/05, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> On 6/23/05, Sebastian Luque <[EMAIL PROTECTED]> wrote:
> > Thanks a lot Martin and Gabor!
> >
> >
> > On Thu, 23 Jun 2005 08:20:44 -0400,
> > Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> >
> > [...]
> >
> > > Also if you are referring to the chron package then
> > > the names of the chron classes are 'dates' and 'times' -- not 'chron'.
> >
> > However, when the object has both dates and times, then the class becomes
> > 'chron', inheriting both 'dates' and 'times':
> >
> > R> class(x)
> > [1] "chron" "dates" "times"
> 
> 
> Did you try the example I posted?  Its self contained and reproducible and
> it inherits from both "dates" and "times" yet there is no "chron" in the class
> vector, at least in that case.
> 

Just to be clear, the point is that you need to be sure that your chron
objects really have class "chron" since one often speaks of chron
objects that are of class dates or times but not chron.

This may or may not be a problem for you but I thought it worthwhile pointing
out just in case.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] classes with chron slots

2005-06-23 Thread Sebastian Luque
On Thu, 23 Jun 2005 10:13:31 -0400,
Gabor Grothendieck <[EMAIL PROTECTED]> wrote:

[...]

> Just to be clear, the point is that you need to be sure that your chron
> objects really have class "chron" since one often speaks of chron
> objects that are of class dates or times but not chron.

That's right, I was just pointing out that there *is* a 'chron' class,
which is an extension of both 'dates' and 'times', as shown by object 'x'
in the examples we were talking about.

Cheers,
-- 
Sebastian P. Luque

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html