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

Hadley Wickham h@wickh@m @ending from gm@il@com
Sun Sep 2 15:08:35 CEST 2018

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.

On Fri, Aug 24, 2018 at 1:03 PM Henrik Bengtsson
<henrik.bengtsson using 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 using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


More information about the R-devel mailing list