[Rd] factor S4 class is NA when as.character method exists

From: Dan Murphy <chiefmurphy_at_gmail.com>
Date: Mon, 23 Jan 2012 07:07:01 -0800


'factor' returns <NA> for my S4 object when the class is given an "as.character" method. Here is a minimal example:

> setClass("foo", contains="numeric")
> bar <- new("foo", 12)
> factor(bar)

[1] 12
Levels: 12
> setMethod("as.character", "foo", function(x) paste("x=", x@.Data))
[1] "as.character"
> as.character(bar)

[1] "x= 12"
> factor(bar)

[1] <NA>
Levels: 12

I would like to 'aggregate' by my S4 objects, but 'factor' seems to be getting in the way. Is there an 'as.character' implementation that works better for S4 classes? I searched help.search("factor S4 class") and help.search("factor S4 as.character") without success.

Thank you.

Dan Murphy

        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 23 Jan 2012 - 15:14:32 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Mon 23 Jan 2012 - 16:50:11 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