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))
43 ## Check trailing '/' problem
44 dbCreate("testRDSdb", "RDS")
45 db <- dbInit("testRDSdb/", "RDS")
48 ######################################################################
49 ## test filehashDB1 class
51 dbCreate("mydb", "DB1")
52 db <- dbInit("mydb", "DB1")
54 ## Put some data into it
56 dbInsert(db, "a", 1:10)
57 dbInsert(db, "b", rnorm(100))
58 dbInsert(db, "c", 100:1)
59 dbInsert(db, "d", runif(1000))
60 dbInsert(db, "other", "hello")
81 tryCatch(print(env$c), error = function(e) print(e))
82 tryCatch(dbFetch(db, "c"), error = function(e) print(e))
85 dbInsert(db, "numbers", numbers)
86 b <- dbFetch(db, "numbers")
87 stopifnot(all.equal(numbers, b))
88 stopifnot(identical(numbers, b))
93 ######################################################################
94 ######################################################################
95 ## Test everything on all database formats
97 types <- c("DB1", "RDS")
101 cat("-----------------\n")
102 cat("-----------------\n")
103 cat("TESTING TYPE", type, "\n")
104 cat("-----------------\n")
105 cat("-----------------\n")
107 name <- paste("mydb", type, sep = "")
109 db <- dbInit(name, type)
111 dbInsert(db, "a", 1:10) ## integer
112 dbInsert(db, "b", rnorm(100)) ## numeric
113 dbInsert(db, "c", 100:1) ## integer
114 dbInsert(db, "d", runif(1000)) ## numeric
115 dbInsert(db, "other", "hello") ## character
117 ## Use extractor/replacement methods
118 db$list <- as.list(1:100)
119 db$dataf <- data.frame(x = rnorm(2000), y = rnorm(2000), z = rnorm(2000))
146 with(db, print(mean(b)))
148 r <- lapply(db, summary)
153 tryCatch(print(env$c), error = function(e) print(e))
154 tryCatch(dbFetch(db, "c"), error = function(e) print(e))
156 numbers <- rnorm(100)
157 dbInsert(db, "numbers", numbers)
158 b <- dbFetch(db, "numbers")
159 stopifnot(all.equal(numbers, b))
160 stopifnot(identical(numbers, b))
170 dbCreate("testLoadingDB", "DB1")
171 db <- dbInit("testLoadingDB", "DB1")
178 dbLoad(db) ## 'a', 'b'
183 db <- dbInit("testLoadingDB", "DB1")
192 ################################################################################
193 ## Check dbReorganize
195 dbCreate("test_reorg", "DB1")
196 db <- dbInit("test_reorg", "DB1")
203 dbInsert(db, "b", rnorm(1000))
204 dbInsert(db, "b", rnorm(1000))
205 dbInsert(db, "b", rnorm(1000))
206 dbInsert(db, "b", rnorm(1000))
207 dbInsert(db, "c", runif(1000))
208 dbInsert(db, "c", runif(1000))
209 dbInsert(db, "c", runif(1000))
210 dbInsert(db, "c", runif(1000))
215 print(file.info(db@datafile)$size)
219 db <- dbInit("test_reorg", "DB1")
221 print(file.info(db@datafile)$size)