Skip to content

Consider serialization #225

Open
Open

Description

@hadley

Extracted out of #222

This is something like:

  • When serializing an R7 object replace the object_class attribute with a placeholder that contains the package and class name.
  • When deserialiazing, need to dynamically look up class from package + class name, and recreate object_class. It would be nice call validate() to check that the save object is compatible with the currently loaded package, but that would require executing code, which isn't a good idea.

We also need provide some general advice in the documentation — if you want your objects to be deserializable in the long-term, what do you need to do?

Activity

  1. lawremi commented on Apr 15, 2022

    @lawremi
    Collaborator

    S4 stores the package as an attribute on class() since it is a scalar. It does not validate on load.

    Simply calling validate() would likely be problematic because the validation code will change along with the current definition, but serialized forms have a frozen and potentially outdated representation. We've discussed registering a hook called upon de-serialization that could automatically upgrade the object to the new form. That would probably mean storing a version on the serialized object though, which introduces some complexity.

    In the past, Bioconductor has gone to great lengths to detect old objects (like a missing slot) and automatically populate the slot with a default value. It has also explored storing the class version as an explicit slot. Neither of those two ideas gained broad adoption.

  2. lawremi commented on Apr 15, 2022

    @lawremi
    Collaborator

    Also, just to clarify a hook would not be "arbitrary code" since it would be a symbol that a registry maps to a function. The registry would be something explicit, not just a namespace, so it wouldn't be possible to e.g. call unlink() with a serialized form of "*". Any malicious code would already need to be installed into the user's package library.

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