Creating a Reproducible Data Object (RDO)

Let’s create a single RDO without any dependencies. Our ROD object will be encapsulating mtcars dataset under different name data_mtcars and the reproducible R code.

Printing the object gives you the name of the object, dependencies if there are any, and statuses.

Let’s add the reproducible code. The code needs to be of expression class. We need simply to wrap our code in expression({ }).

If we changing the code or the cached data the timestamp last changed is updated. Reading the cache changes the last touched timestamp, so we know when the RDO was last used.

We can access the cached data via active binding cache.

The cache is NULL as the code has never been run yet and the data haven’t been cached yet. Let’s do it for the first time…

Implicit validation

After the code was evaluated and the result was cached, the status is validated? changed to TRUE. This is called implicit validation. We can confirm it with is_validated() method.

Getting the code

To access the code as a text we can use code active binding. It returns the RDO (self) but before that it prints out to the console the RDO code.

The print_code() method can give you similar effect.

If you want to get your code as R expressions you can use get_code() method. The returned expression can be than evaluated manually. You can also use run_code(cache = FALSE) method for that purpose. The code will be evaluated but result will not be cached.

Explicit validation

Running the code and caching the result implicitly validating the RDO, but there is also an explicit validation. Explicit Validation is done using validate() method. The method is evaluating the reproducible code and the result is compare to the cached data. If they are the same, the RDO is validated.