Update date
[filehash.git] / tests / reg-tests.Rout.save
blob5681116abd450ffba3e7bb1354cdfb9889b7901c
2 R version 2.8.0 (2008-10-20)
3 Copyright (C) 2008 The R Foundation for Statistical Computing
4 ISBN 3-900051-07-0
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.
16 Type 'q()' to quit R.
18 > library(filehash)
19 filehash: Simple key-value database (2.0-1 2008-12-19)
20
21 > ######################################################################
22 > ## Test 'filehashRDS' class
23
24 > dbCreate("mydbRDS", "RDS")
25 [1] TRUE
26 > db <- dbInit("mydbRDS", "RDS")
27 > show(db)
28 'filehashRDS' database 'mydbRDS'
29
30 > ## Put some data into it
31 > set.seed(1000)
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")
37
38 > dbList(db)
39 [1] "a"     "b"     "c"     "d"     "other"
40
41 > dbExists(db, "e")
42 [1] FALSE
43 > dbExists(db, "a")
44 [1] TRUE
45
46 > env <- db2env(db)
47 > ls(env)
48 [1] "a"     "b"     "c"     "d"     "other"
49
50 > env$a
51  [1]  1  2  3  4  5  6  7  8  9 10
52 > env$b
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
70 > env$c
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
77 > str(env$d)
78  num [1:1000] 0.0854 0.3317 0.5647 0.4989 0.4549 ...
79 > env$other
80 [1] "hello"
81
82 > env$b <- rnorm(100)
83 > mean(env$b)
84 [1] -0.02208835
85
86 > env$a[1:5] <- 5:1
87 > print(env$a)
88  [1]  5  4  3  2  1  6  7  8  9 10
89
90 > dbDelete(db, "c")
91
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'
96
97 > ## Check trailing '/' problem
98 > dbCreate("testRDSdb", "RDS")
99 [1] TRUE
100 > db <- dbInit("testRDSdb/", "RDS")
101 > print(db)
102 'filehashRDS' database 'testRDSdb'
104 > ######################################################################
105 > ## test filehashDB1 class
107 > dbCreate("mydb", "DB1")
108 [1] TRUE
109 > db <- dbInit("mydb", "DB1")
111 > ## Put some data into it
112 > set.seed(1000)
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")
119 > dbList(db)
120 [1] "a"     "b"     "other" "c"     "d"    
122 > env <- db2env(db)
123 > ls(env)
124 [1] "a"     "b"     "c"     "d"     "other"
126 > env$a
127  [1]  1  2  3  4  5  6  7  8  9 10
128 > env$b
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
146 > env$c
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
153 > str(env$d)
154  num [1:1000] 0.0854 0.3317 0.5647 0.4989 0.4549 ...
155 > env$other
156 [1] "hello"
158 > env$b <- rnorm(100)
159 > mean(env$b)
160 [1] -0.02208835
162 > env$a[1:5] <- 5:1
163 > print(env$a)
164  [1]  5  4  3  2  1  6  7  8  9 10
166 > dbDelete(db, "c")
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 > ################################################################################
180 > ## Other tests
182 > rm(list = ls())
185 > dbCreate("testLoadingDB", "DB1")
186 [1] TRUE
187 > db <- dbInit("testLoadingDB", "DB1")
189 > set.seed(234)
191 > db$a <- rnorm(100)
192 > db$b <- runif(1000)
194 > dbLoad(db)  ## 'a', 'b'
195 > summary(a)
196      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
197 -3.036000 -0.642100  0.172000  0.004131  0.614100  2.107000 
198 > summary(b)
199     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
200 0.004583 0.229900 0.478600 0.482200 0.729200 0.999800 
202 > rm(list = ls())
203 > db <- dbInit("testLoadingDB", "DB1")
205 > dbLazyLoad(db)
207 > summary(a)
208      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
209 -3.036000 -0.642100  0.172000  0.004131  0.614100  2.107000 
210 > summary(b)
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")
220 [1] TRUE
221 > db <- dbInit("test_reorg", "DB1")
223 > set.seed(1000)
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))
237 > summary(db$b)
238     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
239 -2.76800 -0.65520 -0.06100 -0.01269  0.65240  3.73900 
240 > summary(db$c)
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)
245 [1] 64980
247 > dbReorganize(db)
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'
250 [1] TRUE
252 > db <- dbInit("test_reorg", "DB1")
254 > print(file.info(db@datafile)$size)
255 [1] 16245
257 > summary(db$b)
258     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
259 -2.76800 -0.65520 -0.06100 -0.01269  0.65240  3.73900 
260 > summary(db$c)
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")
269 [1] TRUE
271 > dbCreate("mydb")
272 [1] TRUE
273 > db <- dbInit("mydb")
275 > set.seed(100)
277 > dbInsert(db, "a", rnorm(100))
278 > value <- dbFetch(db, "a")
279 > mean(value)
280 [1] 0.002912563
282 > dbInsert(db, "b", 123)
283 > dbDelete(db, "a")
284 > dbList(db)
285 [1] "b"
286 > dbExists(db, "a")
287 [1] FALSE
289 > file.remove("mydb")
290 [1] TRUE
292 > ################################################################################
293 > ## Check queue
295 > db <- createQ("testq")
296 > push(db, 1)
297 > push(db, 2)
298 > top(db)
299 [1] 1
301 > pop(db)
302 [1] 1
303 > top(db)
304 [1] 2