modify_by {refer} | R Documentation |
Update the value pointed to by a ref
object. If the new value is a function,
the old values will be applied to the function and overwritten.
modify_by(x, value, ...)
x |
object of class |
value |
new value or function applied to the object at the referenced location |
... |
additional arguments passed to the function |
object of class "ref"
x <- 1:10
ref_to_x <- ref(x)
# Apply the square root function
modify_by(ref_to_x, sqrt)
print(x)
# Overwrite the original values
modify_by(ref_to_x, "hello world!")
print(x)