Let's prepare some set to be archived.
library(ggplot2) library(ggthemes) library(archivist2) createEmptyRepo( "SETS" )
setLocalRepo( "SETS" ) data(iris) plotArtifact <- ggplot( iris, aes(x = Sepal.Length, y = Species)) + geom_point()+ theme_wsj() plotData <- iris plotFunctions <- list( ggplot, geom_point, theme_wsj)
Such set now can be archived using saveSetToRepo
function
saveSetToRepo( artifact = plotArtifact, data = plotData, functions = plotFunctions)
saveSetToRepo
function saves desired set of artifacts to the local Repository
in a given directory.
To learn more about artifacts visit http://pbiecek.github.io/archivist/.
Set is a collection containing
saveSetToRepo
archives artifact
, data
and functions
using saveToRepo
function but additionally it adds Tags
to every part of a set in convention as: set:md5hashOfArtifact
to remember
that all objects came originally from one set. This additional tag helps to restore a set from a Repository
.
As a result of this function a character strings is returned, which determines
the md5hash
of the archived artifact.
saveSetToRepo
uses saveToRepo
function so normally names of elements of a set can not be archived as a name
tag. The names of all archived elements from a set are archived under tag named set:name:
.
One can check archived elements that come only from sets.
showLocalRepo(method = "sets")
Having a tag named set:name
and a tag named set
that specify to which artifacts this element is linked one can restore already archived set with loadSetFromLocalRepo
function (not yet in the archivist package) by giving artifact's md5hash
that is an output of a saveSetToRepo
function.
loadSetFromLocalRepo <- function( md5hash, repoDir = NULL ){ stopifnot( is.character( md5hash ), length( md5hash ) == 1 ) # get hashes artifactHash <- md5hash SetElementsHashes <- searchInLocalRepo( paste0("set:", md5hash ), fixed = FALSE, repoDir = repoDir) # get names artifactName <- getTagsLocal( artifactHash, tag="set:name", repoDir = repoDir) artifactName <- sub(x = artifactName, pattern = "set:name:", replacement = "") SetElementsNames <- sapply( SetElementsHashes, function( element ){ nameElem <- getTagsLocal( md5hash = element, tag="set:name", repoDir = repoDir) sub(x = nameElem, pattern = "set:name:", replacement = "") }) # assign artifact assign( x = artifactName, value = loadFromLocalRepo(artifactHash, repoDir = repoDir, value = TRUE), envir = parent.frame(1)) # assign elements of a set for( i in seq_along(SetElementsNames)){ assign( x = SetElementsNames[i], value = loadFromLocalRepo(SetElementsHashes[i], repoDir = repoDir, value = TRUE), envir = parent.frame(1)) } }
For archived set, let's remove the set from global environment and then let's load a set from Repository
ls()
rm( list = c("plotData", "plotFunctions", "plotArtifact") ) ls()
loadSetFromLocalRepo("f0745effbbedbf160243a154c6339574") ls()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.