Re: [R] why-s of method dispatching
On Wed, 17 Mar 2004, Vadim Ogranovich wrote: I am having a problem to understand why as.data.frame method doesn't dispatch properly on my class: setClass(Foo, character) [1] Foo as.data.frame(list(foo=new(Foo, .Data=a))) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce Foo into a data.frame I was expecting that this would call as.data.frame.character. You have set an S4 class and as.data.frame is an S3 generic. list(foo=new(Foo, .Data=a)) $foo An object of class Foo [1] a and what as.data.frame sees is attributes(list(foo=new(Foo, .Data=a))$foo) $class [1] Foo attr(,package) [1] .GlobalEnv so thinks this is an S3 class it knows nothing about. Another puzzle. If I explicitly call as.data.frame.character() it would fail but for a different reason: as.data.frame.character(list(foo=new(Foo, .Data=a))) Error in unique.default(x) : unique() applies only to vectors I was under an impression that an instance of Foo would be welcome anywhere a character was, but it seems to be more subtle. What am I missing? The difference between S3 and S4 classes. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] why-s of method dispatching
I see. Thank you very much! This brings another question. Does R-Core have any plan to promote data.frame to an S4 class? In general, is there any road-map (formal or informal) to phasing out S3 classes? Thanks, Vadim -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Thursday, March 18, 2004 12:24 AM To: Vadim Ogranovich Cc: R Help List Subject: Re: [R] why-s of method dispatching On Wed, 17 Mar 2004, Vadim Ogranovich wrote: I am having a problem to understand why as.data.frame method doesn't dispatch properly on my class: setClass(Foo, character) [1] Foo as.data.frame(list(foo=new(Foo, .Data=a))) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce Foo into a data.frame I was expecting that this would call as.data.frame.character. You have set an S4 class and as.data.frame is an S3 generic. list(foo=new(Foo, .Data=a)) $foo An object of class Foo [1] a and what as.data.frame sees is attributes(list(foo=new(Foo, .Data=a))$foo) $class [1] Foo attr(,package) [1] .GlobalEnv so thinks this is an S3 class it knows nothing about. Another puzzle. If I explicitly call as.data.frame.character() it would fail but for a different reason: as.data.frame.character(list(foo=new(Foo, .Data=a))) Error in unique.default(x) : unique() applies only to vectors I was under an impression that an instance of Foo would be welcome anywhere a character was, but it seems to be more subtle. What am I missing? The difference between S3 and S4 classes. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] why-s of method dispatching
I see. Thank you very much! Does R-Core have any plan to promote data.frame to an S4 class? In general, is there any road-map (formal or informal) for phasing out S3 classes? Thanks, Vadim -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Thursday, March 18, 2004 12:24 AM To: Vadim Ogranovich Cc: R Help List Subject: Re: [R] why-s of method dispatching On Wed, 17 Mar 2004, Vadim Ogranovich wrote: I am having a problem to understand why as.data.frame method doesn't dispatch properly on my class: setClass(Foo, character) [1] Foo as.data.frame(list(foo=new(Foo, .Data=a))) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce Foo into a data.frame I was expecting that this would call as.data.frame.character. You have set an S4 class and as.data.frame is an S3 generic. list(foo=new(Foo, .Data=a)) $foo An object of class Foo [1] a and what as.data.frame sees is attributes(list(foo=new(Foo, .Data=a))$foo) $class [1] Foo attr(,package) [1] .GlobalEnv so thinks this is an S3 class it knows nothing about. Another puzzle. If I explicitly call as.data.frame.character() it would fail but for a different reason: as.data.frame.character(list(foo=new(Foo, .Data=a))) Error in unique.default(x) : unique() applies only to vectors I was under an impression that an instance of Foo would be welcome anywhere a character was, but it seems to be more subtle. What am I missing? The difference between S3 and S4 classes. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] why-s of method dispatching
Vadim Ogranovich wrote: Does R-Core have any plan to promote data.frame to an S4 class? In general, is there any road-map (formal or informal) for phasing out S3 classes? FOR GOD'S SAKE DON'T!!! S4 classes and methods are incomprehensible to the human mind, which is what I'm equipped with. If S3 is phased out, R will become effectively unusable as a programming language. cheers, Rolf Turner [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] why-s of method dispatching
On Thu, 18 Mar 2004, Vadim Ogranovich wrote: I see. Thank you very much! Does R-Core have any plan to promote data.frame to an S4 class? In general, is there any road-map (formal or informal) for phasing out S3 classes? No, no. There is a vast amount of existing code depending on S3 classes. As you will see from Rolf Turner's reaction, many users wish to keep it that way. BTW, not all of us would see it as promotion, as S3 and S4 classes have different strengths. It is unfortunate that the particular way S4 classes are implemented at present that they get confused with S3 classes. Thanks, Vadim -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Thursday, March 18, 2004 12:24 AM To: Vadim Ogranovich Cc: R Help List Subject: Re: [R] why-s of method dispatching On Wed, 17 Mar 2004, Vadim Ogranovich wrote: I am having a problem to understand why as.data.frame method doesn't dispatch properly on my class: setClass(Foo, character) [1] Foo as.data.frame(list(foo=new(Foo, .Data=a))) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce Foo into a data.frame I was expecting that this would call as.data.frame.character. You have set an S4 class and as.data.frame is an S3 generic. list(foo=new(Foo, .Data=a)) $foo An object of class Foo [1] a and what as.data.frame sees is attributes(list(foo=new(Foo, .Data=a))$foo) $class [1] Foo attr(,package) [1] .GlobalEnv so thinks this is an S3 class it knows nothing about. Another puzzle. If I explicitly call as.data.frame.character() it would fail but for a different reason: as.data.frame.character(list(foo=new(Foo, .Data=a))) Error in unique.default(x) : unique() applies only to vectors I was under an impression that an instance of Foo would be welcome anywhere a character was, but it seems to be more subtle. What am I missing? The difference between S3 and S4 classes. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] why-s of method dispatching
Hi, I am having a problem to understand why as.data.frame method doesn't dispatch properly on my class: setClass(Foo, character) [1] Foo as.data.frame(list(foo=new(Foo, .Data=a))) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce Foo into a data.frame I was expecting that this would call as.data.frame.character. Another puzzle. If I explicitly call as.data.frame.character() it would fail but for a different reason: as.data.frame.character(list(foo=new(Foo, .Data=a))) Error in unique.default(x) : unique() applies only to vectors I was under an impression that an instance of Foo would be welcome anywhere a character was, but it seems to be more subtle. What am I missing? Thanks, Vadim __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html