1### R code from vignette source 'registry.Rnw'
2### Encoding: UTF-8
3
4###################################################
5### code chunk number 1: registry.Rnw:56-58
6###################################################
7options(width = 80)
8library("registry")
9
10
11###################################################
12### code chunk number 2: registry.Rnw:122-125
13###################################################
14library(registry)
15R <- registry()
16print(R)
17
18
19###################################################
20### code chunk number 3: registry.Rnw:141-142
21###################################################
22checkAge <- function(x) stopifnot(is.na(x) || x > 0 && x < 100)
23
24
25###################################################
26### code chunk number 4: registry.Rnw:147-148
27###################################################
28checkPhone <- function(x) stopifnot(!is.na(x$mobile) || !is.na(x$home))
29
30
31###################################################
32### code chunk number 5: registry.Rnw:153-155
33###################################################
34R <- registry(registry_class = "Addressbook", entry_class = "Address",
35              validity_FUN = checkPhone)
36
37
38###################################################
39### code chunk number 6: registry.Rnw:158-164
40###################################################
41print.Addressbook <-
42function(x, ...) {
43    writeLines(sprintf("An address book with %i entries.\n", length(x)))
44    invisible(x)
45}
46print(R)
47
48
49###################################################
50### code chunk number 7: registry.Rnw:170-172
51###################################################
52R$set_field("last", type = "character", is_key = TRUE, index_FUN = match_partial_ignorecase)
53R$set_field("first", type = "character", is_key = TRUE, index_FUN = match_partial_ignorecase)
54
55
56###################################################
57### code chunk number 8: registry.Rnw:175-176
58###################################################
59R$set_field("address", type = "character")
60
61
62###################################################
63### code chunk number 9: registry.Rnw:181-183
64###################################################
65R$set_field("mobile", type = "character")
66R$set_field("home", type = "character")
67
68
69###################################################
70### code chunk number 10: registry.Rnw:187-188
71###################################################
72R$set_field("age", type = "integer", validity_FUN = checkAge)
73
74
75###################################################
76### code chunk number 11: registry.Rnw:192-195
77###################################################
78R$set_field("type", type = "character",
79            alternatives = c("Business", "Private"),
80            default = "Business")
81
82
83###################################################
84### code chunk number 12: registry.Rnw:198-199
85###################################################
86R$get_field("type")
87
88
89###################################################
90### code chunk number 13: registry.Rnw:206-210
91###################################################
92R$set_entry(last = "Smith", first = "Mary", address = "Vienna",
93            home = "734 43 34", type = "Private", age = 44L)
94R$set_entry(last = "Smith", first = "Peter", address = "New York",
95            mobile = "878 78 87")
96
97
98###################################################
99### code chunk number 14: registry.Rnw:213-215
100###################################################
101R$set_entry("Myers", "John", "Washington", "52 32 34", "898 89 99",
102            33L, "Business")
103
104
105###################################################
106### code chunk number 15: registry.Rnw:218-223
107###################################################
108TRY <- function(expr) tryCatch(expr, error = print)
109TRY(R$set_entry(last = "Smith", first = "Mary"))
110TRY(R$set_entry(last = "Miller", first = "Henry"))
111TRY(R$set_entry(last = "Miller", first = "Henry", age = 12.5))
112TRY(R$set_entry(last = "Miller", first = "Henry", age = 999L))
113
114
115###################################################
116### code chunk number 16: registry.Rnw:226-227
117###################################################
118R$get_entry(last = "Smith", first = "mar")
119
120
121###################################################
122### code chunk number 17: registry.Rnw:231-234
123###################################################
124print.Address <- function(x) with(x,
125    writeLines(sprintf("%s %s, %s; home: %s, mobile: %s; age: %i (%s)", first, last, address, home, mobile, age, type)))
126R$get_entry(last = "Smith", first = "mar")
127
128
129###################################################
130### code chunk number 18: registry.Rnw:241-242
131###################################################
132R[["Myers"]]
133
134
135###################################################
136### code chunk number 19: registry.Rnw:246-248
137###################################################
138R$set_entry(last = "Frears", first = c("Joe", "Jonathan"),
139            address = "Washington", home = "721 42 34")
140
141
142###################################################
143### code chunk number 20: registry.Rnw:251-252
144###################################################
145identical(R[["Frears", "Jonathan"]], R[["Frears", "Joe"]])
146
147
148###################################################
149### code chunk number 21: registry.Rnw:258-259
150###################################################
151R$get_entries("Smith")
152
153
154###################################################
155### code chunk number 22: registry.Rnw:262-263
156###################################################
157R$grep_entries("Priv")
158
159
160###################################################
161### code chunk number 23: registry.Rnw:266-268 (eval = FALSE)
162###################################################
163## R$get_entries()
164## R[]
165
166
167###################################################
168### code chunk number 24: registry.Rnw:271-272
169###################################################
170summary(R)
171
172
173###################################################
174### code chunk number 25: registry.Rnw:276-279
175###################################################
176R[["Smith", "Peter"]]
177R$modify_entry(last = "Smith", first = "Peter", age = 22L)
178R[["Smith", "Peter"]]
179
180
181###################################################
182### code chunk number 26: registry.Rnw:282-284
183###################################################
184R$delete_entry(last = "Smith", first = "Peter")
185R[["Smith", "Peter"]]
186
187
188###################################################
189### code chunk number 27: registry.Rnw:294-299
190###################################################
191R$seal_entries()
192TRY(R$delete_entry("Smith", "Mary"))
193R$set_entry(last = "Slater", first = "Christian", address = "Boston",
194            mobile = "766 23 88")
195R[["Slater"]]
196
197
198###################################################
199### code chunk number 28: registry.Rnw:302-307
200###################################################
201R$get_permissions()
202R$restrict_permissions(delete_entries = FALSE)
203TRY(R$delete_entry("Slater"))
204R$modify_entry(last = "Slater", first = "Christian", age = 44L)
205R[["Slater"]]
206
207
208