From hadley at rice.edu  Fri Nov  4 01:36:07 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Fri, 4 Nov 2011 13:36:07 +1300
Subject: [Rd] [R] any updates w.r.t. lapply, sapply,
	apply retaining classes
In-Reply-To: <CAKfbWjv8Zt-JSd=XSHy-HhNSsARp-ZDWH712NuLM3V6dEkQuMA@mail.gmail.com>
References: <CAKfbWjtiSziUMh3sETk6JqDKz2GsrhugGkLcWs=AKSMN+r4_kA@mail.gmail.com>
	<CANz9Z_Js6vQ3VCUG8zXwoSbLfxkhQYzpre=W6pN1TC23pqi8Yw@mail.gmail.com>
	<CAKfbWjv8Zt-JSd=XSHy-HhNSsARp-ZDWH712NuLM3V6dEkQuMA@mail.gmail.com>
Message-ID: <CABdHhvFqwxkM8_DjUdGiB9ympzPFtj8VoviWDyfKbft7LKEMdA@mail.gmail.com>

> ? ?I agree that it is non-trivial to solve the cases you & I have posed.
> ?However, I would wholeheartedly support having an error spit back for any
> function that does not explicitly support a class. ?In this case, if I
> attempt to do ? sapply(x, class), and 'x' is of class "difftime", then I
> should receive an error "sapply cannot function upon class 'difftime' ".
> ?Why do I take this stance? ?There are at least 2 strong reasons:

I don't see why that command should be a problem because class()
returns a string.

A better example might be sapply(x, identity) which in general you
would hope to be identical to x:

x <- structure(1:10, class = "blah")
identical(x, sapply(x, identity))
# [1] FALSE

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] [R] any updates w.r.t. lapply, sapply, apply retaining classes
Hadley Wickham