gptr_preimage() is the S3 generic the object checkpointer calls for a binding of the
workspace before a tool call that runs R code. It decides how the value the binding holds now
is kept, so that a rewind can put it back. Methods are leaf functions: they may read x but
must never store it anywhere.
Usage
gptr_preimage(x, name, ctx, ...)
# Default S3 method
gptr_preimage(x, name, ctx, ...)
# S3 method for class 'data.table'
gptr_preimage(x, name, ctx, ...)Arguments
- x
The object bound to
name.- name
The binding name (a string).
- ctx
A list:
predicted, what the agent's code is predicted to do toname("assign","modify","byref","remove"or"none");bytes, the size ofxin bytes (NAwhen unknown);budget, the largest copy allowed, in bytes. Whenctx$dryisTRUEthe checkpointer only asks whether a capture is possible and a method must not copy.- ...
Unused; for methods.
Value
A list with mode ("ref", "copy" or "none"), reason (a string explaining
"none", else NULL) and copy (the deep copy for "copy", else NULL).
Details
The default method keeps value-semantics objects by reference ("ref": nothing is copied
unless the agent edits the object in place) and reports environments (including R6 and
RefClass objects) and external pointers as not restorable ("none"). The data.table method
returns a deep copy made with data.table::copy() ("copy") when the agent's code is
predicted to modify the table by reference (:=, set*()) and the table fits the budget.
Packages add methods for their own classes with a delayed registration,
S3method(gptr::gptr_preimage, myclass); an R6 class can, for example, return
x$clone(deep = TRUE) as "copy". This generic is experimental.