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

2020-10-07 Thread Jiefei Wang
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))
@0x1f9271c0 13 INTSXP g0c0 [REF(2)] I am altrep
> y[1] <- 1.0
Duplicating object
Coercing object
> .Internal(inspect(y))
@0x1f927c08 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))
@0x1f8ddb20 13 INTSXP g0c0 [REF(2)] I am altrep
> y[1] <- 1.0
> .Internal(inspect(y))
@0x1f0d72a0 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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2020-10-07 Thread Gabriel Becker
Jiefei,

Where does the code for your altrep class live?

Thanks,
~G

On Wed, Oct 7, 2020 at 4:25 AM Jiefei Wang  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))
> @0x1f9271c0 13 INTSXP g0c0 [REF(2)] I am altrep
> > y[1] <- 1.0
> Duplicating object
> Coercing object
> > .Internal(inspect(y))
> @0x1f927c08 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))
> @0x1f8ddb20 13 INTSXP g0c0 [REF(2)] I am altrep
> > y[1] <- 1.0
> > .Internal(inspect(y))
> @0x1f0d72a0 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@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2020-10-07 Thread Jiefei Wang
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  wrote:

> Jiefei,
>
> Where does the code for your altrep class live?
>
> Thanks,
> ~G
>
> On Wed, Oct 7, 2020 at 4:25 AM Jiefei Wang  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))
>> @0x1f9271c0 13 INTSXP g0c0 [REF(2)] I am altrep
>> > y[1] <- 1.0
>> Duplicating object
>> Coercing object
>> > .Internal(inspect(y))
>> @0x1f927c08 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))
>> @0x1f8ddb20 13 INTSXP g0c0 [REF(2)] I am altrep
>> > y[1] <- 1.0
>> > .Internal(inspect(y))
>> @0x1f0d72a0 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@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel