[Rd] Make as.factor an S3 generic?

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Apr 20 20:38:59 CEST 2011


Well, lots of functions are not generic.  We do ask you to give a case 
for such changes ... where is it?

On Wed, 20 Apr 2011, Martin Morgan wrote:

> 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

OS-specific ....

> /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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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, UK                Fax:  +44 1865 272595


More information about the R-devel mailing list