Repository navigation
Description
R7 integration with base R
This issues lays out a minimal set of changes to base R that would allow R7 to exist as a CRAN package.
I think this would be useful because:
-
Allows the community to use R7 for "real" problems and give feedback to use, before R7 moves into base R.
-
If the tidyverse is to use R7, we'll need some way to preserve our backward compatibility guarantees, and a CRAN package would make this easy.
-
If desired, we can use this as a way to provide features for R7 that further differentiate it from S3/S4.
There are few existing extension points that need minor changes to work optimally with R7:
-
@to avoid the currentR7::@hack.
One possible approach be to make@an internal generic when the S4 bit is not set.
The documentation implies that this is already the case. -
inherits()needs to add branch ifwhatis anR7_class. -
Ops double dispatch needs to use
Ops.R7_objectif either object inherits fromR7_object(i.e. the same rule that S4 uses).
We could also consider new extension points (roughly ranked from most to least important):
-
For
serialize(foo):marshall()/unmarshall()--- I think this is a relatively small set of changes?
Need some internal dispatch inWriteItem()andReadItem().
Likely to require bump to serialize version.
(Could also add improvements based on shallow duplicate stuff).
Need to think through security considerations.
And performance considerations? -
For
for(x in foo):iterator()--- have explored some possible approaches with Tomasz Kalinowski at https://github.com/t-kalinowski/r-iterator-ideas.
I think any implementation will be relatively straight forward, but the design will require some thought. -
For
foo():callable()--- I think this would be relatively straightforward change ineval.c. -
For
if (foo):ifable()--- I think this would be relatively straightforward change ineval.c.
Questions:
- Should the new extension points also be available to S3 classes? This is technically trivial (if anything it's easier), but it's worth considering if we want to reserve these as carrots for R7.
Activity
DavisVaughan commentedon Mar 24, 2022
hadley commentedon Mar 29, 2022
No longer sure it's worth trying to make
serialize()/unserialize()generic because of the security implications — I don't think it's reasonable to modifyreadRDS()in such a way that it now might execute arbitrary code, and if you have to opt-in to it, it's not much of an improvement over the status quo. If folks really need custom serialisation for external pointers, @traversc made this proof of concept for using altrep: http://github.com/traversc/CustomSerializationInstead, I think we need to think through the specific changes that R7 will need, which I've started on in #225
hadley commentedon Apr 17, 2023
Thanks to @t-kalinowski the essential extension points have been added to base R, so I've added the optional extras to a new issue: #298.