From @zwj|08 @end|ng |rom gm@||@com  Thu Oct  8 07:58:04 2020
From: @zwj|08 @end|ng |rom gm@||@com (Jiefei Wang)
Date: Thu, 8 Oct 2020 13:58:04 +0800
Subject: [Rd] Coercion function does not work for the ALTREP object
In-Reply-To: <CAD4oTHEERLAPY1Lrd0YoNdQJgfZ7fZr63u++eyJj0w9BFeZDtw@mail.gmail.com>
References: <CAGiFhPOeyN=3KgHEhViR7Jj-ckRqt465QDfjKbDHFvOYJkb0aQ@mail.gmail.com>
 <CAD4oTHEERLAPY1Lrd0YoNdQJgfZ7fZr63u++eyJj0w9BFeZDtw@mail.gmail.com>
Message-ID: <CAGiFhPMLVNe7XWEWu=ioBTyq4XKm9A0PQZbj2jHxptO6OR4ikg@mail.gmail.com>

Hi Gabriel, here is a simple package for reproducing the problem.

https://github.com/Jiefei-Wang/testPkg

Best,
Jiefei

On Thu, Oct 8, 2020 at 5:04 AM Gabriel Becker <gabembecker at gmail.com> wrote:

> 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
Jiefei Wang