2 R version 2.8.0 (2008-10-20)
3 Copyright (C) 2008 The R Foundation for Statistical Computing
6 R is free software and comes with ABSOLUTELY NO WARRANTY.
7 You are welcome to redistribute it under certain conditions.
8 Type 'license()' or 'licence()' for distribution details.
10 R is a collaborative project with many contributors.
11 Type 'contributors()' for more information and
12 'citation()' on how to cite R or R packages in publications.
14 Type 'demo()' for some demos, 'help()' for on-line help, or
15 'help.start()' for an HTML browser interface to help.
19 filehash: Simple key-value database (2.0-1 2008-12-19)
21 > ######################################################################
22 > ## Test 'filehashRDS' class
24 > dbCreate("mydbRDS", "RDS")
26 > db <- dbInit("mydbRDS", "RDS")
28 'filehashRDS' database 'mydbRDS'
30 > ## Put some data into it
32 > dbInsert(db, "a", 1:10)
33 > dbInsert(db, "b", rnorm(100))
34 > dbInsert(db, "c", 100:1)
35 > dbInsert(db, "d", runif(1000))
36 > dbInsert(db, "other", "hello")
39 [1] "a" "b" "c" "d" "other"
48 [1] "a" "b" "c" "d" "other"
51 [1] 1 2 3 4 5 6 7 8 9 10
53 [1] -0.44577826 -1.20585657 0.04112631 0.63938841 -0.78655436 -0.38548930
54 [7] -0.47586788 0.71975069 -0.01850562 -1.37311776 -0.98242783 -0.55448870
55 [13] 0.12138119 -0.12087232 -1.33604105 0.17005748 0.15507872 0.02493187
56 [19] -2.04658541 0.21315411 2.67007166 -1.22701601 0.83424733 0.53257175
57 [25] -0.64682496 0.60316126 -1.78384414 0.33494217 0.56097572 1.22093565
58 [31] -0.21145359 0.69942953 -0.70643668 -0.46515095 -1.76619861 0.18928860
59 [37] -0.36618068 1.05760118 -0.74162146 -1.34835905 -0.51730643 1.41173570
60 [43] 0.18546503 -0.04369144 -0.21591338 1.46377535 0.22966664 0.10762363
61 [49] -1.37810256 -0.96818288 0.25171138 -1.09469370 0.39764284 -0.99630200
62 [55] 0.10057801 0.95368028 -1.79032293 0.31170122 2.55398801 -0.86083776
63 [61] 0.54392844 -0.39233804 1.23544190 1.19608644 -0.49574690 -0.29434122
64 [67] -0.57349748 1.61920873 -0.95692767 0.04123712 -1.49831044 0.66095916
65 [73] 0.28545762 1.38886629 -0.15934361 -0.46091890 0.16843807 1.39549302
66 [79] 0.72842626 0.33508995 1.16927649 0.24796682 -0.35814947 1.38349332
67 [85] 0.41206917 -0.12300786 -0.06622931 -2.32249088 -1.04565650 2.05787502
68 [91] 1.97153237 -1.92099520 0.46212607 -0.16072406 -0.10421153 0.46783940
69 [97] 0.44392082 0.82855281 -0.38705012 2.01893816
71 [1] 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83
72 [19] 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65
73 [37] 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47
74 [55] 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29
75 [73] 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
76 [91] 10 9 8 7 6 5 4 3 2 1
78 num [1:1000] 0.0854 0.3317 0.5647 0.4989 0.4549 ...
88 [1] 5 4 3 2 1 6 7 8 9 10
92 > tryCatch(print(env$c), error = function(e) cat(as.character(e)))
93 Error in dbFetch(db, key): unable to obtain value for key 'c'
94 > tryCatch(dbFetch(db, "c"), error = function(e) cat(as.character(e)))
95 Error in dbFetch(db, "c"): unable to obtain value for key 'c'
97 > ## Check trailing '/' problem
98 > dbCreate("testRDSdb", "RDS")
100 > db <- dbInit("testRDSdb/", "RDS")
102 'filehashRDS' database 'testRDSdb'
104 > ######################################################################
105 > ## test filehashDB1 class
107 > dbCreate("mydb", "DB1")
109 > db <- dbInit("mydb", "DB1")
111 > ## Put some data into it
113 > dbInsert(db, "a", 1:10)
114 > dbInsert(db, "b", rnorm(100))
115 > dbInsert(db, "c", 100:1)
116 > dbInsert(db, "d", runif(1000))
117 > dbInsert(db, "other", "hello")
120 [1] "a" "b" "other" "c" "d"
124 [1] "a" "b" "c" "d" "other"
127 [1] 1 2 3 4 5 6 7 8 9 10
129 [1] -0.44577826 -1.20585657 0.04112631 0.63938841 -0.78655436 -0.38548930
130 [7] -0.47586788 0.71975069 -0.01850562 -1.37311776 -0.98242783 -0.55448870
131 [13] 0.12138119 -0.12087232 -1.33604105 0.17005748 0.15507872 0.02493187
132 [19] -2.04658541 0.21315411 2.67007166 -1.22701601 0.83424733 0.53257175
133 [25] -0.64682496 0.60316126 -1.78384414 0.33494217 0.56097572 1.22093565
134 [31] -0.21145359 0.69942953 -0.70643668 -0.46515095 -1.76619861 0.18928860
135 [37] -0.36618068 1.05760118 -0.74162146 -1.34835905 -0.51730643 1.41173570
136 [43] 0.18546503 -0.04369144 -0.21591338 1.46377535 0.22966664 0.10762363
137 [49] -1.37810256 -0.96818288 0.25171138 -1.09469370 0.39764284 -0.99630200
138 [55] 0.10057801 0.95368028 -1.79032293 0.31170122 2.55398801 -0.86083776
139 [61] 0.54392844 -0.39233804 1.23544190 1.19608644 -0.49574690 -0.29434122
140 [67] -0.57349748 1.61920873 -0.95692767 0.04123712 -1.49831044 0.66095916
141 [73] 0.28545762 1.38886629 -0.15934361 -0.46091890 0.16843807 1.39549302
142 [79] 0.72842626 0.33508995 1.16927649 0.24796682 -0.35814947 1.38349332
143 [85] 0.41206917 -0.12300786 -0.06622931 -2.32249088 -1.04565650 2.05787502
144 [91] 1.97153237 -1.92099520 0.46212607 -0.16072406 -0.10421153 0.46783940
145 [97] 0.44392082 0.82855281 -0.38705012 2.01893816
147 [1] 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83
148 [19] 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65
149 [37] 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47
150 [55] 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29
151 [73] 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
152 [91] 10 9 8 7 6 5 4 3 2 1
154 num [1:1000] 0.0854 0.3317 0.5647 0.4989 0.4549 ...
158 > env$b <- rnorm(100)
164 [1] 5 4 3 2 1 6 7 8 9 10
168 > tryCatch(print(env$c), error = function(e) cat(as.character(e)))
169 Error in readSingleKey(con, map, key): unable to obtain value for key 'c'
170 > tryCatch(dbFetch(db, "c"), error = function(e) cat(as.character(e)))
171 Error in readSingleKey(con, map, key): unable to obtain value for key 'c'
173 > numbers <- rnorm(100)
174 > dbInsert(db, "numbers", numbers)
175 > b <- dbFetch(db, "numbers")
176 > stopifnot(all.equal(numbers, b))
177 > stopifnot(identical(numbers, b))
179 > ################################################################################
185 > dbCreate("testLoadingDB", "DB1")
187 > db <- dbInit("testLoadingDB", "DB1")
192 > db$b <- runif(1000)
194 > dbLoad(db) ## 'a', 'b'
196 Min. 1st Qu. Median Mean 3rd Qu. Max.
197 -3.036000 -0.642100 0.172000 0.004131 0.614100 2.107000
199 Min. 1st Qu. Median Mean 3rd Qu. Max.
200 0.004583 0.229900 0.478600 0.482200 0.729200 0.999800
203 > db <- dbInit("testLoadingDB", "DB1")
208 Min. 1st Qu. Median Mean 3rd Qu. Max.
209 -3.036000 -0.642100 0.172000 0.004131 0.614100 2.107000
211 Min. 1st Qu. Median Mean 3rd Qu. Max.
212 0.004583 0.229900 0.478600 0.482200 0.729200 0.999800
216 > ################################################################################
217 > ## Check dbReorganize
219 > dbCreate("test_reorg", "DB1")
221 > db <- dbInit("test_reorg", "DB1")
224 > dbInsert(db, "a", 1)
225 > dbInsert(db, "a", 1)
226 > dbInsert(db, "a", 1)
227 > dbInsert(db, "a", 1)
228 > dbInsert(db, "b", rnorm(1000))
229 > dbInsert(db, "b", rnorm(1000))
230 > dbInsert(db, "b", rnorm(1000))
231 > dbInsert(db, "b", rnorm(1000))
232 > dbInsert(db, "c", runif(1000))
233 > dbInsert(db, "c", runif(1000))
234 > dbInsert(db, "c", runif(1000))
235 > dbInsert(db, "c", runif(1000))
238 Min. 1st Qu. Median Mean 3rd Qu. Max.
239 -2.76800 -0.65520 -0.06100 -0.01269 0.65240 3.73900
241 Min. 1st Qu. Median Mean 3rd Qu. Max.
242 0.0002346 0.2416000 0.4813000 0.4938000 0.7492000 0.9992000
244 > print(file.info(db@datafile)$size)
248 Reorganizing database: 33% (1/3)
\b\b\b\b\b\b\b\b\b67% (2/3)
\b\b\b\b\b\b\b\b\b100% (3/3)
\b\b\b\b\b\b\b\b\b\b
249 Finished; reload database with 'dbInit'
252 > db <- dbInit("test_reorg", "DB1")
254 > print(file.info(db@datafile)$size)
258 Min. 1st Qu. Median Mean 3rd Qu. Max.
259 -2.76800 -0.65520 -0.06100 -0.01269 0.65240 3.73900
261 Min. 1st Qu. Median Mean 3rd Qu. Max.
262 0.0002346 0.2416000 0.4813000 0.4938000 0.7492000 0.9992000
265 > ################################################################################
266 > ## Taken from the vignette
268 > file.remove("mydb")
273 > db <- dbInit("mydb")
277 > dbInsert(db, "a", rnorm(100))
278 > value <- dbFetch(db, "a")
282 > dbInsert(db, "b", 123)
289 > file.remove("mydb")
292 > ################################################################################
295 > db <- createQ("testq")