What and why?

Everything in R is an object


What if we store all R objects that have been ever created?


Goals for the archivist package:

What the archivist is doing?


The archivist is an R package for management of R objects outside R session. It stores binary copies of R objects in rda files and provides easy access for seeking and restoring these objects based on timestamps, classes or other properties


But, why anybody would like to store copies of all R objects?

Example 1: archivist + knitr

Enrich knitr reports with hooks for selected objects. Example.

archivist::aread("pbiecek/Eseje/arepo/e10f9d223df408fca73ea548456493f4")

Example 2: archivist + shiny

Enrich shiny applications with hooks to displayed plots. Example.

More about this example.

How does it work?

Basics

library(archivist)

createLocalRepo("arepo", default = TRUE)

model <- lm(Sepal.Length ~ Petal.Length + Species, data=iris)
saveToLocalRepo(model)

library(ggplot2)

plot <- ggplot(iris, aes(Sepal.Length, Petal.Length)) + geom_point()
saveToLocalRepo(plot)

# from the default local repository
aread("e700c6704890022a4e0277e11cd46488")

# from the github pbiecek/graphGallery repository
aread("pbiecek/graphGallery/18a98048f0584469483afb65294ce3ed")

models <- asearch("pbiecek/graphGallery", patterns = "class:lm")
modelsBIC <- sapply(models, BIC)
sort(modelsBIC)

The structure

What else you can do with the archivist?

Pedigree of an object

library("dplyr")
iris %a%
 dplyr::filter(Sepal.Length < 6) %a%
 lm(Petal.Length~Species, data=.) %a%
 summary() -> tmp
ahistory(md5hash = "050e41ec3bc40b3004bc6bdd356acae7", format = "kable", alink = TRUE)
ahistory(tmp)

You need a village to raise an R object

asession("050e41ec3bc40b3004bc6bdd356acae7")
# restoreLibs("pbiecek/graphGallery/arepo/600bda83cb840947976bd1ce3a11879d")

Other features

createLocalRepo("allModels", default = TRUE)
trace(lm, exit = quote(saveToLocalRepo(z, repoDir="allModels")))
addHooksToPrint(class=c("ggplot", "data.frame"),
  repoDir = "arepo",
  repo = "Eseje", user = "pbiecek", subdir = "arepo")

structure

Thank you!

Find more at pbiecek.github.io/archivist



pbiecek/archivist documentation built on May 25, 2021, 11:36 p.m.