[Rd] Make as.factor an S3 generic?
Martin Morgan
mtmorgan at fhcrc.org
Wed Apr 20 18:56:03 CEST 2011
as.factor / as.ordered is not written as a generic. This differs from
as.numeric, as.matrix, and other as.*. The following seems to address
this and does not break make check-all.
FWIW, the patch is against r55563, because with r55564 I see
/home/mtmorgan/src/R-devel/src/main/dounzip.c:75:15: error: storage size
of ‘dt’ isn’t known
/home/mtmorgan/src/R-devel/src/main/dounzip.c:88:5: warning: implicit
declaration of function ‘mktime’
make[3]: *** [dounzip.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory `/home/mtmorgan/bin/R-devel/src/main'
make[2]: *** [R] Error 2
make[2]: Leaving directory `/home/mtmorgan/bin/R-devel/src/main'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/home/mtmorgan/bin/R-devel/src'
make: *** [R] Error 1
Index: src/library/base/R/factor.R
===================================================================
--- src/library/base/R/factor.R (revision 55563)
+++ src/library/base/R/factor.R (working copy)
@@ -45,7 +45,9 @@
}
is.factor <- function(x) inherits(x, "factor")
-as.factor <- function(x) if (is.factor(x)) x else factor(x)
+as.factor.default <- function(x, ...)
+ if (is.factor(x)) x else factor(x, ...)
+as.factor <- function(x, ...) UseMethod("as.factor")
## Help old S users:
category <- function(...) .Defunct()
@@ -245,7 +247,10 @@
ordered <- function(x, ...) factor(x, ..., ordered=TRUE)
is.ordered <- function(x) inherits(x, "ordered")
-as.ordered <- function(x) if(is.ordered(x)) x else ordered(x)
+as.ordered.default <- function(x, ...)
+ if(is.ordered(x)) x else ordered(x, ...)
+as.ordered <- function(x, ...)
+ UseMethod("as.ordered")
Ops.ordered <- function (e1, e2)
{
Index: src/library/base/man/factor.Rd
===================================================================
--- src/library/base/man/factor.Rd (revision 55563)
+++ src/library/base/man/factor.Rd (working copy)
@@ -10,7 +10,9 @@
\alias{is.factor}
\alias{is.ordered}
\alias{as.factor}
+\alias{as.factor.default}
\alias{as.ordered}
+\alias{as.ordered.default}
\alias{is.na<-.factor}
\alias{Math.factor}
\alias{Ops.factor}
@@ -40,8 +42,8 @@
is.factor(x)
is.ordered(x)
-as.factor(x)
-as.ordered(x)
+as.factor(x, \dots)
+as.ordered(x, \dots)
addNA(x, ifany=FALSE)
}
--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
Location: M1-B861
Telephone: 206 667-2793
More information about the R-devel
mailing list