From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Mon Nov 18 09:18:00 2019
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Mon, 18 Nov 2019 09:18:00 +0100
Subject: [Rd] BUG?: A copy of base::`+` (primitive) is not a clone but a
 "pointer"
In-Reply-To: <CAFDcVCRthz6=XjH8=RZm85+BKHKzrVsrz9ZTUSWvi7As2U=hdA@mail.gmail.com>
References: <CAFDcVCRthz6=XjH8=RZm85+BKHKzrVsrz9ZTUSWvi7As2U=hdA@mail.gmail.com>
Message-ID: <24018.21432.337451.272740@stat.math.ethz.ch>

>>>>> Henrik Bengtsson 
>>>>>     on Sun, 17 Nov 2019 14:31:07 -0800 writes:

    > $ R --vanilla R version 3.6.1 (2019-07-05) -- "Action of
    > the Toes" Copyright (C) 2019 The R Foundation for
    > Statistical Computing Platform: x86_64-pc-linux-gnu
    > (64-bit) ...

    >> str(base::`+`)
    > function (e1, e2)

    >> plus <- structure(base::`+`, class = "plus") str(plus)
    > function (e1, e2) - attr(*, "class")= chr "plus"

    > ## Hmm ...
    >> str(base::`+`)
    > function (e1, e2) - attr(*, "class")= chr "plus"

    >> class(base::`+`) <- NULL str(base::`+`)
    > function (e1, e2)

    > ## Hmm ...
    >> str(plus)
    > function (e1, e2)

    > Even without assigning to `plus`, you get this behavior:

    > $ R --vanilla
    >> structure(base::`+`, class = "plus")
    > function (e1, e2) .Primitive("+") attr(,"class") [1]
    > "plus"

    > # Hmm...
    >> str(base::`+`)
    > function (e1, e2) - attr(*, "class")= chr "plus"

    > Looks to be the case for common (all?) .Primitive
    > functions.

No need for 'base::' (who would be crazy enough to redefine `+`?)
nor str() actually:

attr(`+`, "class") <- NULL  # (reset)
`+`
structure(`+`, class = "plus")
`+`

is clearly convincing and minimal

> attr(`+`, "class") <- NULL
> `+`
function (e1, e2)  .Primitive("+")
> structure(`+`, class = "plus")
function (e1, e2)  .Primitive("+")
attr(,"class")
[1] "plus"
> `+`
function (e1, e2)  .Primitive("+")
attr(,"class")
[1] "plus"
> 

---------------------------------------------------------

    > Is this expected? 

no.  (at least not by 99.999% of R users)


    > Should I report this one to Bugzilla?
yes, please.

    > /Henrik



[Rd] BUG?: A copy of base::`+` (primitive) is not a clone but a "pointer"
Martin Maechler