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

iuke-tier@ey m@iii@g oii uiow@@edu iuke-tier@ey m@iii@g oii uiow@@edu
Fri Oct 9 00:10:43 CEST 2020


For larger atomic vectors (currently >= 64 elements) the complex
assignment process tries to avoid duplicating when only attributes are
updated, This is done with an ALTREP wrapper. The differences in
whether the Duplicate method are called for smaller and larger vectors
are therefore as intended, Ideally there should be no difference for
Coerce. There is a difference because wrappers currently don't
delegate the Coerce method when the wrapped object is an ALTREP. I'll
look into whether that can be addressed without breaking things.

Best,

luke

On Thu, 8 Oct 2020, Jiefei Wang wrote:

> 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 using 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 using 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 using r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney using uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list