You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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.
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.
Activity
lawremi commentedon Apr 15, 2022
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.
lawremi commentedon Apr 15, 2022
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.