From h@wickh@m @ending from gm@il@com  Sun Sep  2 15:08:35 2018
From: h@wickh@m @ending from gm@il@com (Hadley Wickham)
Date: Sun, 2 Sep 2018 08:08:35 -0500
Subject: [Rd] True length - length(unclass(x)) - without having to call
 unclass()?
In-Reply-To: <CAFDcVCQdmLYM4gPj_zoz4KeoHGGUzJux9hLK_3vMVaeWUsrHQQ@mail.gmail.com>
References: <CAFDcVCQdmLYM4gPj_zoz4KeoHGGUzJux9hLK_3vMVaeWUsrHQQ@mail.gmail.com>
Message-ID: <CABdHhvEQTOO=+qmwad+0aJb5WTzF2BFQhN5Lde9NgyiTNrsfWg@mail.gmail.com>

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 you should never discuss in public
?) is temporarily setting the object bit to FALSE.

In the long run, I think an ALTREP vector that exposes the underlying
data of an S3 object (i.e. sans attributes apart from names) is
probably the way forward.

Hadley
On Fri, Aug 24, 2018 at 1:03 PM Henrik Bengtsson
<henrik.bengtsson at gmail.com> 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 calling unclass(x) may trigger an
> expensive copy internally in some cases.  Is that concern unfounded?
>
> Thxs,
>
> Henrik
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
http://hadley.nz



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