archivist (version 1.0)

rmFromRepo: Remove an Artifact Given as md5hash from a Repository

Description

rmFromRepo removes an artifact given as md5hash from a Repository. To learn more about artifacts visit archivist-package.

Usage

rmFromRepo(md5hash, repoDir, removeData = FALSE, removeMiniature = FALSE,
  force = FALSE)

Arguments

md5hash
A character assigned to the artifact as a result of a cryptographical hash function with MD5 algorithm, or it's abbreviation. This object will be removed.
repoDir
A character denoting an existing directory from which an artifact will be removed.
removeData
A logical value denoting whether to remove a data with the artifact specified by the md5hash. Defualt FALSE.
removeMiniature
A logical value denoting whether to remove a miniature with the artifact specified by the md5hash. Defualt FALSE.
force
A logical value denoting whether to remove data if it is related to more than 1 artifact. Defualt FALSE.

Details

rmFromRepo removes an artifact given as md5hash from a Repository, which is a SQLite database named backpack - created by a createEmptyRepo call. For every artifact, md5hash is a unique string of length 32 that comes out as a result of digest function, which uses a cryptographical MD5 hash algorithm.

Also this function removes a md5hash.rda file, where md5hash is the artifact's hash as above.

Important: instead of giving the whole md5hash character, the user can simply give first few characters of the md5hash. For example, a09dd instead of a09ddjdkf9kj33dcjdnfjgos9jd9jkcv. All artifacts with the same corresponing md5hash abbreviation will be removed from the Repository and from the gallery folder.

rmFromRepo provides functionality that enables to delete miniatures of the artifacts (.txt or .png files) while removing .rda files. To disable this functionality use removeMiniature = FALSE. Also, if the data from the artifact were archived, the data will be removed by default but there is a possibility not to delete this data while performing rmFromRepo - simply use removeData = TRUE.

rmFromRepo provides functionality that enables to delete miniatures of the artifacts (.txt or .png files) while removing .rda files. To delete miniature use removeMiniature = TRUE. Also if the data from the artifact was archived, there is a possibility to delete this data while removing artifact that uses this data. Simply use removeData = TRUE.

If one wants to remove all artifact created between two dates, it is suggested to perform:

  • obj2rm <- searchInLocalRepo( tag = list(dateFrom, dateTo), repoDir = )
  • sapply(obj2rm, rmFromRepo, repoDir = )

See Also

Other archivist: Repository; Tags; archivist-package; copyGithubRepo, copyLocalRepo; createEmptyRepo; deleteRepo; loadFromGithubRepo, loadFromLocalRepo; md5hash; saveToRepo; searchInGithubRepo, searchInLocalRepo; showGithubRepo, showLocalRepo; summaryGithubRepo, summaryLocalRepo

Examples

Run this code
# objects preparation
data.frame object
data(iris)

# ggplot/gg object
library(ggplot2)
df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),y = rnorm(30))
library(plyr)
ds <- ddply(df, .(gp), summarise, mean = mean(y), sd = sd(y))
myplot123 <- ggplot(df, aes(x = gp, y = y)) +
  geom_point() +  geom_point(data = ds, aes(y = mean),
                             colour = 'red', size = 3)

# lm object
model <- lm(Sepal.Length~ Sepal.Width + Petal.Length + Petal.Width, data= iris)
model2 <- lm(Sepal.Length~ Sepal.Width + Petal.Width, data= iris)
model3 <- lm(Sepal.Length~ Sepal.Width, data= iris)

# agnes (twins) object
library(cluster)
data(votes.repub)
agn1 <- agnes(votes.repub, metric = "manhattan", stand = TRUE)

# fanny (partition) object
x <- rbind(cbind(rnorm(10, 0, 0.5), rnorm(10, 0, 0.5)),
           cbind(rnorm(15, 5, 0.5), rnorm(15, 5, 0.5)),
           cbind(rnorm( 3,3.2,0.5), rnorm( 3,3.2,0.5)))
fannyx <- fanny(x, 2)

# creating example Repository - that examples will work

exampleRepoDir <- tempdir()
createEmptyRepo(repoDir = exampleRepoDir)
myplo123Md5hash <- saveToRepo(myplot123, repoDir=exampleRepoDir)
irisMd5hash <- saveToRepo(iris, repoDir=exampleRepoDir)
modelMd5hash  <- saveToRepo(model, repoDir=exampleRepoDir)
agn1Md5hash <- saveToRepo(agn1, repoDir=exampleRepoDir)
fannyxMd5hash <- saveToRepo(fannyx, repoDir=exampleRepoDir)

# let's see how the Repository look like: show
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)
showLocalRepo(method = "tags", repoDir = exampleRepoDir)

# let's see how the Repository look like: summary
summaryLocalRepo( exampleRepoDir )

# remove examples

rmFromRepo(fannyxMd5hash, repoDir = exampleRepoDir, removeData= FALSE)
# removeData = FALSE provides from removing archived "fannyxMd5hash object"-data from
# a Repository and gallery

rmFromRepo(irisMd5hash, repoDir = exampleRepoDir)
# note that also files in gallery folder, created in exampleRepoDir
# directory will be removed

# let's see how the Repository look like: show
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)
showLocalRepo(method = "tags", repoDir = exampleRepoDir)

# let's see how the Repository look like: summary
summaryLocalRepo( exampleRepoDir )


# one can have the same object archived 3 different times
# there will appear a warning message
agn1Md5hash2 <- saveToRepo(agn1, repoDir=exampleRepoDir)
agn1Md5hash3 <- saveToRepo(agn1, repoDir=exampleRepoDir)

# md5hashes are the same for that same object (agn1)
agn1Md5hash == agn1Md5hash2
agn1Md5hash2 == agn1Md5hash3



# but there are 3 times more rows in Repository database (backpack.db).

# let's see how the Repository look like: show
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)
showLocalRepo(method = "tags", repoDir = exampleRepoDir)

# let's see how the Repository look like: summary
summaryLocalRepo( exampleRepoDir )

# one easy call removes them all but this call will result in error
rmFromRepo(agn1Md5hash, repoDir = exampleRepoDir, removeData = TRUE,
            removeMiniature = TRUE)

# soultion to that is
rmFromRepo(agn1Md5hash, repoDir = exampleRepoDir, removeData = TRUE,
            removeMiniature = TRUE, force = TRUE)
# removeMiniature = TRUE removes miniatures from gallery folder

# rest of artifacts can be removed e.g. like this
# looking for dates of creation and then removing all objects
# from specific date

obj2rm <- searchInLocalRepo( pattern = list(dateFrom = Sys.Date(), dateTo = Sys.Date()),
                             repoDir = exampleRepoDir )
sapply(obj2rm, rmFromRepo, repoDir = exampleRepoDir)
# above example removed all objects from this example

# let's see how the Repository look like: show
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)
showLocalRepo(method = "tags", repoDir = exampleRepoDir)

# one can also remove objects from only specific class
modelMd5hash  <- saveToRepo(model, repoDir=exampleRepoDir)
model2Md5hash  <- saveToRepo(model2, repoDir=exampleRepoDir)
model3Md5hash  <- saveToRepo(model3, repoDir=exampleRepoDir)
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)

objMd5hash <- searchInLocalRepo("class:lm", repoDir = exampleRepoDir)
sapply(objMd5hash, rmFromRepo, repoDir = exampleRepoDir, removeData = TRUE, force = TRUE)
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)
summaryLocalRepo( exampleRepoDir )


# once can remove object specifying only its md5hash abbreviation
(myplo123Md5hash <- saveToRepo(myplot123, repoDir=exampleRepoDir))
showLocalRepo(method = "md5hashes", repoDir = exampleRepoDir)
# "ff751bb5ba34bbb8a7851958b15f2ef7"
# so example abbreviation might be : "ff751"
rmFromRepo("ff751", repoDir = exampleRepoDir)
summaryLocalRepo( repoDir = exampleRepoDir )


# removing an example Repository

deleteRepo( exampleRepoDir )

rm( exampleRepoDir )

Run the code above in your browser using DataCamp Workspace