3 ######################################################################
4 ## Test 'filehashRDS' class
6 dbCreate("mydbRDS", "RDS")
7 db <- dbInit("mydbRDS", "RDS")
10 ## Put some data into it
12 dbInsert(db, "a", 1:10)
13 dbInsert(db, "b", rnorm(100))
14 dbInsert(db, "c", 100:1)
15 dbInsert(db, "d", runif(1000))
16 dbInsert(db, "other", "hello")
40 tryCatch(print(env$c), error = function(e) print(e))
41 tryCatch(dbFetch(db, "c"), error = function(e) print(e))
44 ######################################################################
45 ## test filehashDB1 class
47 dbCreate("mydb", "DB1")
48 db <- dbInit("mydb", "DB1")
50 ## Put some data into it
52 dbInsert(db, "a", 1:10)
53 dbInsert(db, "b", rnorm(100))
54 dbInsert(db, "c", 100:1)
55 dbInsert(db, "d", runif(1000))
56 dbInsert(db, "other", "hello")
77 tryCatch(print(env$c), error = function(e) print(e))
78 tryCatch(dbFetch(db, "c"), error = function(e) print(e))
81 dbInsert(db, "numbers", numbers)
82 b <- dbFetch(db, "numbers")
83 stopifnot(all.equal(numbers, b))
84 stopifnot(identical(numbers, b))
89 ######################################################################
90 ######################################################################
91 ## Test everything on all database formats
93 types <- c("DB1", "RDS")
97 cat("-----------------\n")
98 cat("-----------------\n")
99 cat("TESTING TYPE", type, "\n")
100 cat("-----------------\n")
101 cat("-----------------\n")
103 name <- paste("mydb", type, sep = "")
105 db <- dbInit(name, type)
107 dbInsert(db, "a", 1:10) ## integer
108 dbInsert(db, "b", rnorm(100)) ## numeric
109 dbInsert(db, "c", 100:1) ## integer
110 dbInsert(db, "d", runif(1000)) ## numeric
111 dbInsert(db, "other", "hello") ## character
113 ## Use extractor/replacement methods
114 db$list <- as.list(1:100)
115 db$dataf <- data.frame(x = rnorm(2000), y = rnorm(2000), z = rnorm(2000))
142 with(db, print(mean(b)))
144 r <- lapply(db, summary)
149 tryCatch(print(env$c), error = function(e) print(e))
150 tryCatch(dbFetch(db, "c"), error = function(e) print(e))
152 numbers <- rnorm(100)
153 dbInsert(db, "numbers", numbers)
154 b <- dbFetch(db, "numbers")
155 stopifnot(all.equal(numbers, b))
156 stopifnot(identical(numbers, b))
166 dbCreate("testLoadingDB", "DB1")
167 db <- dbInit("testLoadingDB", "DB1")
174 dbLoad(db) ## 'a', 'b'
179 db <- dbInit("testLoadingDB", "DB1")
188 ################################################################################
189 ## Check dbReorganize
191 dbCreate("test_reorg", "DB1")
192 db <- dbInit("test_reorg", "DB1")
199 dbInsert(db, "b", rnorm(1000))
200 dbInsert(db, "b", rnorm(1000))
201 dbInsert(db, "b", rnorm(1000))
202 dbInsert(db, "b", rnorm(1000))
203 dbInsert(db, "c", runif(1000))
204 dbInsert(db, "c", runif(1000))
205 dbInsert(db, "c", runif(1000))
206 dbInsert(db, "c", runif(1000))
211 print(file.info(db@datafile)$size)
215 db <- dbInit("test_reorg", "DB1")
217 print(file.info(db@datafile)$size)