Re: [Rd] as.list method for by Objects

2018-02-03 Thread Henrik Bengtsson
On Fri, Feb 2, 2018 at 12:07 AM, Martin Maechler wrote: >> Henrik Bengtsson >> on Thu, 1 Feb 2018 10:26:23 -0800 writes: > > > On Thu, Feb 1, 2018 at 12:14 AM, Martin Maechler > > wrote: >

Re: [Rd] as.list method for by Objects

2018-02-02 Thread Martin Maechler
> Henrik Bengtsson > on Thu, 1 Feb 2018 10:26:23 -0800 writes: > On Thu, Feb 1, 2018 at 12:14 AM, Martin Maechler > wrote: >>> Michael Lawrence >>> on Tue, 30 Jan 2018

Re: [Rd] as.list method for by Objects

2018-02-01 Thread Henrik Bengtsson
On Thu, Feb 1, 2018 at 12:14 AM, Martin Maechler wrote: >> Michael Lawrence >> on Tue, 30 Jan 2018 15:57:42 -0800 writes: > > > I just meant that the minimal contract for as.list() appears to be that > it > > returns a

Re: [Rd] as.list method for by Objects

2018-02-01 Thread Martin Maechler
> Michael Lawrence > on Thu, 1 Feb 2018 06:12:20 -0800 writes: > On Thu, Feb 1, 2018 at 1:21 AM, Martin Maechler > wrote: >> > Michael Lawrence >> > on Tue, 30 Jan 2018

Re: [Rd] as.list method for by Objects

2018-02-01 Thread Michael Lawrence
On Thu, Feb 1, 2018 at 1:21 AM, Martin Maechler wrote: > > Michael Lawrence > > on Tue, 30 Jan 2018 10:37:38 -0800 writes: > > > I agree that it would make sense for the object to have c("by", > "list") as > > its class

Re: [Rd] as.list method for by Objects

2018-02-01 Thread Martin Maechler
> Michael Lawrence > on Tue, 30 Jan 2018 10:37:38 -0800 writes: > I agree that it would make sense for the object to have c("by", "list") as > its class attribute, since the object is known to behave as a list. Well, but that (list behavior)

Re: [Rd] as.list method for by Objects

2018-02-01 Thread Martin Maechler
> Michael Lawrence > on Tue, 30 Jan 2018 15:57:42 -0800 writes: > I just meant that the minimal contract for as.list() appears to be that it > returns a VECSXP. To the user, we might say that is.list() will always > return TRUE. Indeed. I

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Michael Lawrence
I just meant that the minimal contract for as.list() appears to be that it returns a VECSXP. To the user, we might say that is.list() will always return TRUE. I'm not sure we can expect consistency across methods beyond that, nor is it feasible at this point to match the semantics of the methods

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Michael Lawrence
by() does not always return a list. In Gabe's example, it returns an integer, thus it is coerced to a list. as.list() means that it should be a VECSXP, not necessarily with "list" in the class attribute. Michael On Tue, Jan 30, 2018 at 2:41 PM, Hervé Pagès wrote: > Hi

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Hervé Pagès
Hi Gabe, Interestingly the behavior of as.list() on by objects seem to depend on the object itself: > b1 <- by(1:2, 1:2, identity) > class(as.list(b1)) [1] "list" > b2 <- by(warpbreaks[, 1:2], warpbreaks[,"tension"], summary) > class(as.list(b2)) [1] "by" This is with R 3.4.3 and R devel

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Gabriel Becker
Dario, What version of R are you using. In my mildly old 3.4.0 installation and in the version of Revel I have lying around (also mildly old...) I don't see the behavior I think you are describing > b = by(1:2, 1:2, identity) > class(as.list(b)) [1] "list" > sessionInfo() R Under

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Hervé Pagès
On 01/30/2018 02:24 PM, Hervé Pagès wrote: I agree that it makes sense to expect as.list() to perform a "strict coercion" i.e. to return an object of class "list", *even* on a list derivative. That's what as( , "list") does by default:   # on a data.frame object   as(data.frame(), "list")  #

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Hervé Pagès
I agree that it makes sense to expect as.list() to perform a "strict coercion" i.e. to return an object of class "list", *even* on a list derivative. That's what as( , "list") does by default: # on a data.frame object as(data.frame(), "list") # object of class "list"

Re: [Rd] as.list method for by Objects

2018-01-30 Thread Michael Lawrence
I agree that it would make sense for the object to have c("by", "list") as its class attribute, since the object is known to behave as a list. However, it would may be too disruptive to make this change at this point. Hard to predict. Michael On Mon, Jan 29, 2018 at 5:00 PM, Dario Strbenac

[Rd] as.list method for by Objects

2018-01-29 Thread Dario Strbenac
Good day, I'd like to suggest the addition of an as.list method for a by object that actually returns a list of class "list". This would make it safer to do type-checking, because is.list also returns TRUE for a data.frame variable and using class(result) == "list" is an alternative that only