Array: Class: Array

Description Usage Format Fields Author(s) References Examples

Description

Class representing arrays.

Usage

1

Format

1
2
Class 'R6ClassGenerator' <environment: 0x0000000007b42690> 
 - attr(*, "name")= chr "Array_generator"

Fields

.array

list. List that serves as an array container.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

http://github.com/Rappster/arrayr

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
## Not run: 

##------------------------------------------------------------------------------
## Initialize
##------------------------------------------------------------------------------

## Default //
inst <- Array$new()
inst$.array

## Explicit //
inst <- Array$new(list(a = 1, b = 2))
inst$.array
inst <- Array$new(list(c = 1), list(d = 2))
inst$.array

## Atomic and mixed //
inst <- Array$new(a = 1, b = 2)
inst$.array
inst <- Array$new(a = 1, list(b = 2))
inst$.array

##------------------------------------------------------------------------------
## Add //
##------------------------------------------------------------------------------

## Single //
inst <- Array$new()
inst$add(list(a = 1))
inst$.array
inst$add(list(b = 2))
inst$.array

inst$add(list(b = 2), dups = FALSE)
inst$.array
try(inst$add(list(b = 2), dups = FALSE, strict = 1))
inst$.array
try(inst$add(list(b = 2), dups = FALSE, strict = 2))
inst$.array

inst$add(list(b = 2))
inst$.array

## Single atomic //
inst <- Array$new()
inst$add(1)
inst$.array
inst$add(new.env())
inst$.array
inst$add(a = new.env())
inst$.array
inst$add(b = 1)
inst$.array

## Multiple //
inst <- Array$new()
inst$add(list(a = 1), list(b = 2))
inst$.array

inst$add(1, 1, 1, id = c("c", "d", "e"))
inst$.array

inst$add(1, 1, 1, id = c("e", "f"), dups = FALSE)
inst$.array

inst <- Array$new()
inst$add(1, 1, 1, id = c("a", "b"))
try(inst$add(1, 1, 1, id = c("a", "b"), strict = 1))
try(inst$add(1, 1, 1, id = c("a", "b"), strict = 2))

##------------------------------------------------------------------------------
## Set //
##------------------------------------------------------------------------------

## Single //
inst <- Array$new(list(a = 1))
inst$set(list(a = 2))
inst$.array
inst$set(list(b = 2))
try(inst$set(list(b = 2), strict = 1))
try(inst$set(list(b = 2), strict = 2))
inst$.array

## Multiple //
inst <- Array$new(list(a = 1, b = 1))
inst$set(list(a = 2), list(b = 2))
inst$.array

inst <- Array$new(list(a = 1, b = 1, c = 1))
inst$set(2, 2, 2, id = c("a", "b", "c"))
inst$.array

inst$set(2, 2, 2, id = c("a", "b", "d"))
inst$.array
try(inst$set(2, 2, 2, id = c("a", "b", "d"), strict = 1))
try(inst$set(2, 2, 2, id = c("a", "b", "d"), strict = 2))

## Different lengths //
inst$set(2, 2, 2, id = c("b", "c"))
try(inst$set(2, 2, 2, id = c("b", "c"), strict = 1))
try(inst$set(2, 2, 2, id = c("b", "c"), strict = 2))

## New (or does not have to exist) //
inst <- Array$new(list(a = 1))
inst$set(list(b = 1), must_exist = FALSE)
inst$.array
inst$set(list(c = 1, d = 1), must_exist = FALSE)
inst$.array

##------------------------------------------------------------------------------
## Get //
##------------------------------------------------------------------------------

inst <- Array$new()
inst$get()

inst <- Array$new(array = list(a = 1, b = 1))
inst$.array, list(a = 1, b = 1))
inst$get()

inst$get("a")
inst$get("a", inner = FALSE)
inst$get(c("a", "b"))
inst$get(c("a", "b"), inner = FALSE)
inst$get("c")
inst$get("c", inner = FALSE)
inst$get(c("a", "c"))
inst$get(c("a", "c"), inner = FALSE)

inst <- Array$new(list(a = 1))
inst$get("b")
try(inst$get("b", strict = 1))
try(inst$get("b", strict = 2))
inst$get(c("a", "b"))
try(inst$get(c("a", "b"), strict = 1))
try(inst$get(c("a", "b"), strict = 2))

##------------------------------------------------------------------------------
## Exists //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1, b = 1))
inst$exists("a")
inst$exists(c("a", "b"))
inst$exists("c")

##------------------------------------------------------------------------------
## Index //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1, b = 1))
inst$index("a")
inst$index(c("a", "b"))
inst$index("c")
try(inst$index("c", strict = 1))
try(inst$index("c", strict = 2))
inst$index(c("a", "c"))

inst$index("c", simplify = TRUE)
try(inst$index("c", simplify = TRUE, strict = 1))
try(inst$index("c", simplify = TRUE, strict = 2))
inst$index(c("a", "c"), simplify = TRUE)

##------------------------------------------------------------------------------
## Clear //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1, b = 1))
inst$clear()
inst$.array

##------------------------------------------------------------------------------
## Remove //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rm("a")
inst$exists("a")
inst$rm(c("b", "c"))
inst$rm("a")
inst$rm(c("a", "b"))
inst$add(list(a = 1))
inst$rm(c("a", "b"))
inst$rm("a")
try(inst$rm("a", strict = 1))
try(inst$rm("a", strict = 2))

##------------------------------------------------------------------------------
## Remove first //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmFirst()
inst$get()
inst$rmFirst(2)
inst$get()

inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmFirst(4)
inst$get()
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
try(inst$rmFirst(4, strict = 1))
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
try(inst$rmFirst(4, strict = 2))
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmFirst(4, simplify = TRUE)
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmFirst(3, simplify = TRUE)
inst$get()

inst$rmFirst()
inst$get()
  
##------------------------------------------------------------------------------
## Remove last //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmLast()
inst$get()
inst$rmLast(2)
inst$get()

## Simplify //
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmLast(simplify = TRUE)
inst$get()
inst$rmLast(2, simplify = TRUE)
inst$get()

inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmLast(4)
inst$get()
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
try(inst$rmLast(4, strict = 1))
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
try(inst$rmLast(4, strict = 2))

## Simplify //
inst <- Array$new(array = list(a = 1, b = 1, c = 1))
inst$rmLast(4, simplify = TRUE)
inst$get()

inst <- Array$new()
inst$rmLast()
try(inst$rmLast(strict = 1))
try(inst$rmLast(strict = 2))
inst$rmLast(2)
try(inst$rmLast(strict = 1))
try(inst$rmLast(strict = 2))
inst$get()

## Simplify //
inst <- Array$new()
inst$rmLast(simplify = TRUE)
try(inst$rmLast(strict = 1, simplify = TRUE))
inst$rmLast(2, simplify = TRUE)
try(inst$rmLast(strict = 1, simplify = TRUE))

##------------------------------------------------------------------------------
## Copy //
##------------------------------------------------------------------------------

inst <- Array$new(array = list(a = 1))
inst$copy("a", "b")
inst$get()

inst$copy("c", "d")
inst$get()
try(inst$copy("c", "d", strict = 1))
try(inst$copy("c", "d", strict = 2))

inst$copy(c("a", "b"), c("c", "d"))
inst$get()
inst$copy(c("a", "b"), c("c", "d"), dups = FALSE)
inst$get()
try(inst$copy(c("a", "b"), c("c", "d"), dups = FALSE, strict = 1))
try(inst$copy(c("a", "b"), c("c", "d"), dups = FALSE, strict = 2))
inst$copy(c("a", "b"), c("c", "d"))
inst$get()

inst$copy(c("a", "b"), "d")
try(inst$copy(c("a", "b"), "d", strict = 1))
try(inst$copy(c("a", "b"), "d", strict = 2))


## End(Not run)

rappster/arrayr documentation built on May 26, 2019, 11:09 p.m.