weakref creates a new weak reference, a special type of R object that
associates a value with a key. The value is kept alive for as long as the
key remains reachable (i.e. has yet to be garbage collected), even if the
value itself is no longer referenced.
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)