[R] printing difftime summary

R. Michael Weylandt michael.weylandt at gmail.com
Fri Nov 23 10:13:36 CET 2012


On Thu, Nov 22, 2012 at 5:49 PM, Sam Steingold <sds at gnu.org> wrote:
>> * R. Michael Weylandt <zvpunry.jrlynaqg at tznvy.pbz> [2012-11-22 12:11:55 +0000]:
>>
>>> I now think that what I want is
>>> --8<---------------cut here---------------start------------->8---
>>> difftime.summary <- function (v) {
>>>   s <- summary(as.numeric(v))
>>>   r <- as.data.frame(sapply(s,difftime2string),stringsAsFactors=FALSE)
>>>   names(r) <- c("string")
>>>   r[[units(v)]] <- s
>>>   r
>>> }
>>
>> Any reason not summary.difftime to get S3 dispatch?
>
> I hoped that someone will ask this :-)
>
> 1. because its argument has type "vector of difftime", not "difftime"
> (coming from CLOS, I do not expect summary(vector of difftime) to
> dispatch to summary.difftime, but to summary.vector.of.difftime or something)

I'm not sure that's a suitable distinction in R. (Almost) All objects
are vectors (either generic or atomic) and all that....

>
> 2. because difftime.summary returns a data.frame and not a
> "Classes 'summaryDefault', 'table'" as I assume summary must return.

See http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-should-I-write-summary-methods_003f

>
> if these are not valid issues, then I wonder why my function should not
> be the system default method.
>
> --
> Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
> http://www.childpsy.net/ http://memri.org http://honestreporting.com
> http://jihadwatch.org http://openvotingconsortium.org http://ffii.org
> Sex is like air.  It's only a big deal if you can't get any.




More information about the R-help mailing list