[Rd] Coercion function does not work for the ALTREP object

Jiefei Wang @zwj|08 @end|ng |rom gm@||@com
Wed Oct 7 13:24:52 CEST 2020


Hi all,

The coercion function defined for the ALTREP object will not be called by R
when an assignment operation implicitly introduces coercion for a large
ALTREP object.

For example, If I create a vector of length 10, the ALTREP coercion
function seems to work fine.
```
> x <- 1:10
> y <- wrap_altrep(x)
> .Internal(inspect(y))
@0x000000001f9271c0 13 INTSXP g0c0 [REF(2)] I am altrep
> y[1] <- 1.0
Duplicating object
Coercing object
> .Internal(inspect(y))
@0x000000001f927c08 14 REALSXP g0c0 [REF(1)] I am altrep
```

However, if I create a vector of length 1024, R will give me a normal
real-type vector
```
> x <- 1:1024
> y <- wrap_altrep(x)
> .Internal(inspect(y))
@0x000000001f8ddb20 13 INTSXP g0c0 [REF(2)] I am altrep
> y[1] <- 1.0
> .Internal(inspect(y))
@0x000000001f0d72a0 14 REALSXP g0c7 [REF(1)] (len=1024, tl=0) 1,2,3,4,5,...
```

Note that the duplicate function is also called for the first example. It
seems like R completely ignores my ALTREP functions in the second example.
I feel this might be designed on purpose, but I do not understand the
reason behind it. Is there any reason why we are not consistent here? Here
is my session info

sessionInfo()
R Under development (unstable) (2020-09-03 r79126)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Best,
Jiefei

	[[alternative HTML version deleted]]



More information about the R-devel mailing list