[Rd] ALTREP wrappers and factors

Bemis, Kylie k@bem|@ @end|ng |rom northe@@tern@edu
Wed Jul 17 16:39:49 CEST 2019


Hello,

I’m experimenting with ALTREP and was wondering if there is a preferred way to create an ALTREP wrapper vector without using .Internal(wrap_meta(…)), which R CMD check doesn’t like since it uses an .Internal() function.

I was trying to create a factor that used an ALTREP integer, but attempting to set the class and levels attributes always ended up duplicating and materializing the integer vector. Using the wrapper avoided this issue.

Here is my initial ALTREP integer vector:

> fc0 <- factor(c("a", "a", "b"))
>
> y <- matter::as.matter(as.integer(fc0))
> y <- matter:::as.altrep(y)
>
> .Internal(inspect(y))
@7fb0ce78c0f0 13 INTSXP g0c0 [NAM(7)] matter vector (mode=3, len=3, mem=0)

Here is what I get without a wrapper:

> fc1 <- structure(y, class="factor", levels=levels(x))
> .Internal(inspect(fc1))
@7fb0cae66408 13 INTSXP g0c2 [OBJ,NAM(2),ATT] (len=3, tl=0) 1,1,2
ATTRIB:
  @7fb0ce771868 02 LISTSXP g0c0 []
    TAG: @7fb0c80043d0 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "class" (has value)
    @7fb0c9fcbe90 16 STRSXP g0c1 [NAM(7)] (len=1, tl=0)
      @7fb0c80841a0 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "factor"
    TAG: @7fb0c8004050 01 SYMSXP g1c0 [MARK,NAM(7),LCK,gp=0x4000] "levels" (has value)
    @7fb0d1dd58c8 16 STRSXP g0c2 [MARK,NAM(7)] (len=2, tl=0)
      @7fb0c81bf4c0 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "a"
      @7fb0c90ba728 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "b"

Here is what I get with a wrapper:

> fc2 <- structure(.Internal(wrap_meta(y, 0, 0)), class="factor", levels=levels(x))
> .Internal(inspect(fc2))
@7fb0ce764630 13 INTSXP g0c0 [OBJ,NAM(2),ATT]  wrapper [srt=0,no_na=0]
  @7fb0ce78c0f0 13 INTSXP g0c0 [NAM(7)] matter vector (mode=3, len=3, mem=0)
ATTRIB:
  @7fb0ce764668 02 LISTSXP g0c0 []
    TAG: @7fb0c80043d0 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "class" (has value)
    @7fb0c9fcb010 16 STRSXP g0c1 [NAM(7)] (len=1, tl=0)
      @7fb0c80841a0 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "factor"
    TAG: @7fb0c8004050 01 SYMSXP g1c0 [MARK,NAM(7),LCK,gp=0x4000] "levels" (has value)
    @7fb0d1dd58c8 16 STRSXP g0c2 [MARK,NAM(7)] (len=2, tl=0)
      @7fb0c81bf4c0 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "a"
      @7fb0c90ba728 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "b"

Is there a way to do this that doesn’t rely on .Internal() and won’t produce R CMD check warnings?

~~~
Kylie Ariel Bemis
Khoury College of Computer Sciences
Northeastern University
kuwisdelu.github.io<https://kuwisdelu.github.io>











	[[alternative HTML version deleted]]



More information about the R-devel mailing list