[Rd] Make as.factor an S3 generic?

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Wed, 20 Apr 2011 09:56:03 -0700


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


  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


-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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 20 Apr 2011 - 17:02:44 GMT

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 Wed 20 Apr 2011 - 18:50:49 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