weakref creates a new weak reference - a special type of R object that
associates a Value with a Key. Value is kept alive for as long as Key
remains reachable (i.e. has yet to be garbage collected), even if Value
itself no longer has any references.
weakref_key retrieves the key associated with a weak reference.
weakref_value retrieves the value associated with a weak reference.
Usage
weakref(key, value)
weakref_key(w)
weakref_value(w)
Value
For weakref: a weak reference.
For weakref_key and weakref_value: the key or value
associated with the weak reference, or NULL if no longer reachable.
Arguments
key
a reference object (such as an environment or external pointer).
k <- new.env()
v <- "value"
w <- weakref(k, v)
w
typeof(w)
key <- weakref_key(w)
identical(key, k)
value <- weakref_value(w)
identical(value, v)
rm(v)
weakref_value(w)