Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-10 Thread Iñaki Ucar
El lun., 10 sept. 2018 a las 14:18, Tomas Kalibera () escribió: > > On 09/05/2018 11:18 AM, Iñaki Ucar wrote: > > The bottomline here is that one can always call a base method, > > inexpensively and without modifying the object, in, let's say, > > *formal* OOP languages. In R, this is not possible

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-10 Thread Tomas Kalibera
On 09/05/2018 11:18 AM, Iñaki Ucar wrote: The bottomline here is that one can always call a base method, inexpensively and without modifying the object, in, let's say, *formal* OOP languages. In R, this is not possible in general. It would be possible if there was always a foo.default, but

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-05 Thread luke-tierney
On Wed, 5 Sep 2018, Kevin Ushey wrote: More generally, I think one of the issues is that R is not yet able to decrement a reference count (or mark a 'shared' data object as 'unshared' after it knows only one binding to it exists). This means passing variables to R closures will mark that object

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-05 Thread Kevin Ushey
More generally, I think one of the issues is that R is not yet able to decrement a reference count (or mark a 'shared' data object as 'unshared' after it knows only one binding to it exists). This means passing variables to R closures will mark that object as shared: x <- list()

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-05 Thread Iñaki Ucar
The bottomline here is that one can always call a base method, inexpensively and without modifying the object, in, let's say, *formal* OOP languages. In R, this is not possible in general. It would be possible if there was always a foo.default, but primitives use internal dispatch. I was

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-05 Thread Tomas Kalibera
On 08/24/2018 07:55 PM, Henrik Bengtsson wrote: Is there a low-level function that returns the length of an object 'x' - the length that for instance .subset(x) and .subset2(x) see? An obvious candidate would be to use: .length <- function(x) length(unclass(x)) However, I'm concerned that

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-03 Thread Tomas Kalibera
On 09/03/2018 03:59 PM, Dénes Tóth wrote: Hi Tomas, On 09/03/2018 11:49 AM, Tomas Kalibera wrote: Please don't do this to get the underlying vector length (or to achieve anything else). Setting/deleting attributes of an R object without checking the reference count violates R semantics, which

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-03 Thread Dénes Tóth
Hi Tomas, On 09/03/2018 11:49 AM, Tomas Kalibera wrote: Please don't do this to get the underlying vector length (or to achieve anything else). Setting/deleting attributes of an R object without checking the reference count violates R semantics, which in turn can have unpredictable results on

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-03 Thread Radford Neal
Regarding the discussion of getting length(unclass(x)) without an unclassed version of x being created... There are already no copies done for length(unclass(x)) in pqR (current version of 2017-06-09 at pqR-project.org, as well as the soon-to-be-release new version). This is part of a more

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-03 Thread Tomas Kalibera
Please don't do this to get the underlying vector length (or to achieve anything else). Setting/deleting attributes of an R object without checking the reference count violates R semantics, which in turn can have unpredictable results on R programs (essentially undebuggable segfaults now or

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-02 Thread Hadley Wickham
For the new vctrs::records class, I implemented length, names, [[, and [[<- myself in https://github.com/r-lib/vctrs/blob/master/src/fields.c. That lets me override the default S3 methods while still being able to access the underlying data that I'm interested in. Another option that avoids (that

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-01 Thread Dénes Tóth
The solution below introduces a dependency on data.table, but otherwise it does what you need: --- # special method for Foo objects length.Foo <- function(x) { length(unlist(x, recursive = TRUE, use.names = FALSE)) } # an instance of a Foo object x <- structure(list(a = 1, b = list(b1 = 1,

[Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-08-24 Thread Henrik Bengtsson
Is there a low-level function that returns the length of an object 'x' - the length that for instance .subset(x) and .subset2(x) see? An obvious candidate would be to use: .length <- function(x) length(unclass(x)) However, I'm concerned that calling unclass(x) may trigger an expensive copy