1 R version 2.5.1 (2007-06-27)
2 Copyright (C) 2007 The R Foundation for Statistical Computing
5 R is free software and comes with ABSOLUTELY NO WARRANTY.
6 You are welcome to redistribute it under certain conditions.
7 Type 'license()' or 'licence()' for distribution details.
9 R is a collaborative project with many contributors.
10 Type 'contributors()' for more information and
11 'citation()' on how to cite R or R packages in publications.
13 Type 'demo()' for some demos, 'help()' for on-line help, or
14 'help.start()' for an HTML browser interface to help.
18 Simple key-value database (1.1 2008-04-30)
20 > ######################################################################
21 > ## Test 'filehashRDS' class
23 > dbCreate("mydbRDS", "RDS")
25 > db <- dbInit("mydbRDS", "RDS")
27 'filehashRDS' database 'mydbRDS'
29 > ## Put some data into it
31 > dbInsert(db, "a", 1:10)
32 > dbInsert(db, "b", rnorm(100))
33 > dbInsert(db, "c", 100:1)
34 > dbInsert(db, "d", runif(1000))
35 > dbInsert(db, "other", "hello")
38 [1] "a" "b" "c" "d" "other"
47 [1] "a" "b" "c" "d" "other"
50 [1] 1 2 3 4 5 6 7 8 9 10
52 [1] -0.44577826 -1.20585657 0.04112631 0.63938841 -0.78655436 -0.38548930
53 [7] -0.47586788 0.71975069 -0.01850562 -1.37311776 -0.98242783 -0.55448870
54 [13] 0.12138119 -0.12087232 -1.33604105 0.17005748 0.15507872 0.02493187
55 [19] -2.04658541 0.21315411 2.67007166 -1.22701601 0.83424733 0.53257175
56 [25] -0.64682496 0.60316126 -1.78384414 0.33494217 0.56097572 1.22093565
57 [31] -0.21145359 0.69942953 -0.70643668 -0.46515095 -1.76619861 0.18928860
58 [37] -0.36618068 1.05760118 -0.74162146 -1.34835905 -0.51730643 1.41173570
59 [43] 0.18546503 -0.04369144 -0.21591338 1.46377535 0.22966664 0.10762363
60 [49] -1.37810256 -0.96818288 0.25171138 -1.09469370 0.39764284 -0.99630200
61 [55] 0.10057801 0.95368028 -1.79032293 0.31170122 2.55398801 -0.86083776
62 [61] 0.54392844 -0.39233804 1.23544190 1.19608644 -0.49574690 -0.29434122
63 [67] -0.57349748 1.61920873 -0.95692767 0.04123712 -1.49831044 0.66095916
64 [73] 0.28545762 1.38886629 -0.15934361 -0.46091890 0.16843807 1.39549302
65 [79] 0.72842626 0.33508995 1.16927649 0.24796682 -0.35814947 1.38349332
66 [85] 0.41206917 -0.12300786 -0.06622931 -2.32249088 -1.04565650 2.05787502
67 [91] 1.97153237 -1.92099520 0.46212607 -0.16072406 -0.10421153 0.46783940
68 [97] 0.44392082 0.82855281 -0.38705012 2.01893816
70 [1] 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83
71 [19] 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65
72 [37] 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47
73 [55] 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29
74 [73] 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
75 [91] 10 9 8 7 6 5 4 3 2 1
77 num [1:1000] 0.0854 0.3317 0.5647 0.4989 0.4549 ...
87 [1] 5 4 3 2 1 6 7 8 9 10
91 > tryCatch(print(env$c), error = function(e) cat(as.character(e)))
92 Error in dbFetch(db, key): unable to obtain value for key 'c'
93 > tryCatch(dbFetch(db, "c"), error = function(e) cat(as.character(e)))
94 Error in dbFetch(db, "c"): unable to obtain value for key 'c'
96 > ## Check trailing '/' problem
97 > dbCreate("testRDSdb", "RDS")
99 > db <- dbInit("testRDSdb/", "RDS")
101 'filehashRDS' database 'testRDSdb'
103 > ######################################################################
104 > ## test filehashDB1 class
106 > dbCreate("mydb", "DB1")
108 > db <- dbInit("mydb", "DB1")
110 > ## Put some data into it
112 > dbInsert(db, "a", 1:10)
113 > dbInsert(db, "b", rnorm(100))
114 > dbInsert(db, "c", 100:1)
115 > dbInsert(db, "d", runif(1000))
116 > dbInsert(db, "other", "hello")
119 [1] "a" "b" "other" "c" "d"
123 [1] "a" "b" "c" "d" "other"
126 [1] 1 2 3 4 5 6 7 8 9 10
128 [1] -0.44577826 -1.20585657 0.04112631 0.63938841 -0.78655436 -0.38548930
129 [7] -0.47586788 0.71975069 -0.01850562 -1.37311776 -0.98242783 -0.55448870
130 [13] 0.12138119 -0.12087232 -1.33604105 0.17005748 0.15507872 0.02493187
131 [19] -2.04658541 0.21315411 2.67007166 -1.22701601 0.83424733 0.53257175
132 [25] -0.64682496 0.60316126 -1.78384414 0.33494217 0.56097572 1.22093565
133 [31] -0.21145359 0.69942953 -0.70643668 -0.46515095 -1.76619861 0.18928860
134 [37] -0.36618068 1.05760118 -0.74162146 -1.34835905 -0.51730643 1.41173570
135 [43] 0.18546503 -0.04369144 -0.21591338 1.46377535 0.22966664 0.10762363
136 [49] -1.37810256 -0.96818288 0.25171138 -1.09469370 0.39764284 -0.99630200
137 [55] 0.10057801 0.95368028 -1.79032293 0.31170122 2.55398801 -0.86083776
138 [61] 0.54392844 -0.39233804 1.23544190 1.19608644 -0.49574690 -0.29434122
139 [67] -0.57349748 1.61920873 -0.95692767 0.04123712 -1.49831044 0.66095916
140 [73] 0.28545762 1.38886629 -0.15934361 -0.46091890 0.16843807 1.39549302
141 [79] 0.72842626 0.33508995 1.16927649 0.24796682 -0.35814947 1.38349332
142 [85] 0.41206917 -0.12300786 -0.06622931 -2.32249088 -1.04565650 2.05787502
143 [91] 1.97153237 -1.92099520 0.46212607 -0.16072406 -0.10421153 0.46783940
144 [97] 0.44392082 0.82855281 -0.38705012 2.01893816
146 [1] 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83
147 [19] 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65
148 [37] 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47
149 [55] 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29
150 [73] 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
151 [91] 10 9 8 7 6 5 4 3 2 1
153 num [1:1000] 0.0854 0.3317 0.5647 0.4989 0.4549 ...
157 > env$b <- rnorm(100)
163 [1] 5 4 3 2 1 6 7 8 9 10
167 > tryCatch(print(env$c), error = function(e) cat(as.character(e)))
168 Error in readSingleKey(con, map, key): unable to obtain value for key 'c'
169 > tryCatch(dbFetch(db, "c"), error = function(e) cat(as.character(e)))
170 Error in readSingleKey(con, map, key): unable to obtain value for key 'c'
172 > numbers <- rnorm(100)
173 > dbInsert(db, "numbers", numbers)
174 > b <- dbFetch(db, "numbers")
175 > stopifnot(all.equal(numbers, b))
176 > stopifnot(identical(numbers, b))
178 > ################################################################################
184 > dbCreate("testLoadingDB", "DB1")
186 > db <- dbInit("testLoadingDB", "DB1")
191 > db$b <- runif(1000)
193 > dbLoad(db) ## 'a', 'b'
195 Min. 1st Qu. Median Mean 3rd Qu. Max.
196 -3.036000 -0.642100 0.172000 0.004131 0.614100 2.107000
198 Min. 1st Qu. Median Mean 3rd Qu. Max.
199 0.004583 0.229900 0.478600 0.482200 0.729200 0.999800
202 > db <- dbInit("testLoadingDB", "DB1")
207 Min. 1st Qu. Median Mean 3rd Qu. Max.
208 -3.036000 -0.642100 0.172000 0.004131 0.614100 2.107000
210 Min. 1st Qu. Median Mean 3rd Qu. Max.
211 0.004583 0.229900 0.478600 0.482200 0.729200 0.999800
215 > ################################################################################
216 > ## Check dbReorganize
218 > dbCreate("test_reorg", "DB1")
220 > db <- dbInit("test_reorg", "DB1")
223 > dbInsert(db, "a", 1)
224 > dbInsert(db, "a", 1)
225 > dbInsert(db, "a", 1)
226 > dbInsert(db, "a", 1)
227 > dbInsert(db, "b", rnorm(1000))
228 > dbInsert(db, "b", rnorm(1000))
229 > dbInsert(db, "b", rnorm(1000))
230 > dbInsert(db, "b", rnorm(1000))
231 > dbInsert(db, "c", runif(1000))
232 > dbInsert(db, "c", runif(1000))
233 > dbInsert(db, "c", runif(1000))
234 > dbInsert(db, "c", runif(1000))
237 Min. 1st Qu. Median Mean 3rd Qu. Max.
238 -2.76800 -0.65520 -0.06100 -0.01269 0.65240 3.73900
240 Min. 1st Qu. Median Mean 3rd Qu. Max.
241 0.0002346 0.2416000 0.4813000 0.4938000 0.7492000 0.9992000
243 > print(file.info(db@datafile)$size)
247 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
248 Finished; reload database with 'dbInit'
251 > db <- dbInit("test_reorg", "DB1")
253 > print(file.info(db@datafile)$size)
257 Min. 1st Qu. Median Mean 3rd Qu. Max.
258 -2.76800 -0.65520 -0.06100 -0.01269 0.65240 3.73900
260 Min. 1st Qu. Median Mean 3rd Qu. Max.
261 0.0002346 0.2416000 0.4813000 0.4938000 0.7492000 0.9992000