# 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 )
######
######
REMOVING MANY ARTIFACTS
######
######
# lm object
model <- lm(Sepal.Length~ Sepal.Width + Petal.Length + Petal.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)
# lda object
library(MASS)
Iris <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
Sp = rep(c("s","c","v"), rep(50,3)))
train <- c(8,83,115,118,146,82,76,9,70,139,85,59,78,143,68,
134,148,12,141,101,144,114,41,95,61,128,2,42,37,
29,77,20,44,98,74,32,27,11,49,52,111,55,48,33,38,
113,126,24,104,3,66,81,31,39,26,123,18,108,73,50,
56,54,65,135,84,112,131,60,102,14,120,117,53,138,5)
lda1 <- lda(Sp ~ ., Iris, prior = c(1,1,1)/3, subset = train)
# qda object
tr <- c(7,38,47,43,20,37,44,22,46,49,50,19,4,32,12,29,27,34,2,1,17,13,3,35,36)
train <- rbind(iris3[tr,,1], iris3[tr,,2], iris3[tr,,3])
cl <- factor(c(rep("s",25), rep("c",25), rep("v",25)))
qda1 <- qda(train, cl)
# glmnet object
library( glmnet )
zk=matrix(rnorm(100*20),100,20)
bk=rnorm(100)
glmnet1=glmnet(zk,bk)
# creating example Repository - that examples will work
# need few artifacts to remove
exampleRepoDir <- tempdir()
createEmptyRepo( repoDir = exampleRepoDir )
saveToRepo( iris, repoDir=exampleRepoDir )
saveToRepo( model, repoDir=exampleRepoDir )
saveToRepo( agn1, repoDir=exampleRepoDir )
saveToRepo( fannyx, repoDir=exampleRepoDir )
saveToRepo( lda1, repoDir=exampleRepoDir )
saveToRepo( glmnet1, repoDir=exampleRepoDir )
allUniqueMd5hashes <- unique(showLocalRepo(exampleRepoDir)[,1])
allUniqueMd5hashes
rmFromRepo(allUniqueMd5hashes, many = TRUE, repoDir = exampleRepoDir)
unique(showLocalRepo(exampleRepoDir)[,1])
rm( exampleRepoDir )
Run the code above in your browser using DataLab