library(objectdiff)

Tracked Environments

When performing changes to R objects, just like in any programming languages, the changes become "lost" because the objects get overwritten. However, it may be very helpful to track changes you are making to your objects, so you can "roll back" to earlier versions.

The tracked_environment object provided by this package is like a normal R environment, except it remembers any changes that were made. It is also smart about recording the changes, keeping a minimal memory footprint that tries to avoid full object duplication.

env <- tracked_environment()
env$data <- iris
commit(env) <- "Initial data" # To save changes, you have to "commit",
 # just like in source control systems.
env$data[1, 1] <- 1
commit(env) <- "Changed a value"
env$data[1, 1] <- 2
commit(env) <- "Overwrote same value"
print(env$data[1, 1])

Now we can go back in time!

rollback(env) <- 1 # Go back one commit
print(env$data[1, 1])

For more help, see the documentation by typing ?tracked_environment in the R console.



robertzk/objectdiff documentation built on May 27, 2019, 10:35 a.m.