[Rd] [External] Re: Change to I() in R 4.1

iuke-tier@ey m@iii@g oii uiow@@edu iuke-tier@ey m@iii@g oii uiow@@edu
Fri Oct 30 18:48:24 CET 2020


On Fri, 30 Oct 2020, Pages, Herve wrote:

>
> On 10/29/20 23:08, Pages, Herve wrote:
> ...
>>
>> I can think of 2 ways to move forward:
>>
>> 1. Keep I()'s current implementation but suppress the warning. We'll
>> make the necessary adjustments to DataFrame() to repair columns supplied
>> as I(<S4>) objects. Note that we would still be in the situation where
>> I(<S4>) objects break validObject() but we've been in that situation for
>> years and so far we've managed to work around it. However this doesn't
>> mean that validObject() shouldn't be fixed. Note that print(I(<S4>))
>> would also need to be fixed (it says "<S4 Type Object>" which is
>> misleading). Anyways, these 2 issues are separated from the main issue
>> and can be dealt with later.
>
> 1b. A variant of the above could be to use the old implementation for S4
> objects only:
>
>   I <- function(x)
>   {
>       if (isS4(x)) {
>           structure(x, class = unique.default(c("AsIs", oldClass(x))))
>       } else {
>           `class<-`(x, unique.default(c("AsIs", oldClass(x))))
>       }
>   }
>
> That is probably a good compromise for now.

Not really. The underlying problem is that class<- and attributes<-
(which is what structure() uses) handle the 'class' attribute
differently, and that needs to be fixed. I don't have a strong opinion
on what either should do, but they should do the same thing.

It's probably worth re-thinking the I() mechanism. ?Modifying the
value, whether by changing the class or an attribute, is going to be
brittle. A little less so for an attribute, but using an attribute
rules out dispatch on the AsIs property.

Best,

luke

>
> I would also suggest that the "package" attribute of the S4 class be
> kept around so the code that we use to restore the original object has a
> way to restore it exactly, including its full class specification. Right
> now, and also with the previous implementation, we cannot do that
> because attr(class(x), "package") is lost. So something like this:
>
>   I <- function(x)
>   {
>       if (isS4(x)) {
>           x_class <- class(x)
>           new_classes <- c("AsIs", x_class)
>           attr(new_classes, "package") <- attr(x_class, "package")
>           structure(x, class=new_classes)
>       } else {
>           `class<-`(x, unique.default(c("AsIs", oldClass(x))))
>       }
>   }
>
> Thanks,
> H.
>
>
>

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