From g@bembecker @end|ng |rom gm@||@com  Wed Oct  7 23:04:32 2020
From: g@bembecker @end|ng |rom gm@||@com (Gabriel Becker)
Date: Wed, 7 Oct 2020 14:04:32 -0700
Subject: [Rd] Coercion function does not work for the ALTREP object
In-Reply-To: <CAGiFhPOeyN=3KgHEhViR7Jj-ckRqt465QDfjKbDHFvOYJkb0aQ@mail.gmail.com>
References: <CAGiFhPOeyN=3KgHEhViR7Jj-ckRqt465QDfjKbDHFvOYJkb0aQ@mail.gmail.com>
Message-ID: <CAD4oTHEERLAPY1Lrd0YoNdQJgfZ7fZr63u++eyJj0w9BFeZDtw@mail.gmail.com>

Jiefei,

Where does the code for your altrep class live?

Thanks,
~G

On Wed, Oct 7, 2020 at 4:25 AM Jiefei Wang <szwjf08 at gmail.com> wrote:

> 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]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



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