Skip to content

Base R extension points #222

Closed
Closed

Description

@hadley

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 current R7::@ 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 if what is an R7_class.

  • Ops double dispatch needs to use Ops.R7_object if either object inherits from R7_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 in WriteItem() and ReadItem().
    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 in eval.c.

  • For if (foo): ifable() --- I think this would be relatively straightforward change in eval.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

  1. DavisVaughan commented on Mar 24, 2022

    @DavisVaughan
  2. hadley commented on Mar 29, 2022

    @hadley
    MemberAuthor

    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 modify readRDS() 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/CustomSerialization

    Instead, I think we need to think through the specific changes that R7 will need, which I've started on in #225

  3. hadley commented on Apr 17, 2023

    @hadley
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions