omapR | R Documentation |
A map is given by keys and values.
new()
Creates a new omapR
object.
omapR$new(keys, values, duplicated = "drop", checks = TRUE)
keys
keys, a character vector without NA
value
values
values, a list of R objects; keys
and
values
must have the same length
duplicated
the action to perform for duplicated keys, one of
"drop"
, "join"
, or "separate"
checks
Boolean, whether to check keys
and values
An omapR
object.
omapR$new( keys = c("z", "a"), values = list(c(1, 2), c(3, 4, 5)) ) # examples with duplicated keys: omapR$new( keys = c("a", "a", "b"), values = list(c(1, 2), c(3, 4), c(5, 6)) ) omapR$new( keys = c("a", "a", "b"), values = list(c(1, 2), c(3, 4), c(5, 6)), duplicated = "join" ) omapR$new( keys = c("a", "a", "b"), values = list(c(1, 2), c(3, 4), c(5, 6)), duplicated = "separate" )
print()
Show instance of an omapR
object.
omapR$print(...)
...
ignored
size()
Size of the reference map.
omapR$size()
An integer, the number of entries.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$size()
keys()
Get all keys.
omapR$keys()
The keys, a character vector.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$keys()
values()
Get all values.
omapR$values()
The values, a list of numeric vectors.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$values()
items()
Get all entries of the reference map.
omapR$items()
The entries in a dataframe.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$items()
toList()
Converts the map to a named list.
omapR$toList()
A named list.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$toList()
at()
Returns the 'maybe' value corresponding to the given key.
omapR$at(key)
key
a key (string)
A maybe
value, either the value corresponding to the key
as a 'Just' maybe
value if the key is found, otherwise the
'Nothing' maybe
value.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$at("b") from_just(map$at("b")) map$at("x")
index()
Returns the index of the given key.
omapR$index(key)
key
a key (string)
The index of the key, or NA
if it is not found.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$index("b") map$index("x")
extract()
Extract a submap from the reference map.
omapR$extract(keys, inplace = FALSE, bydeleting = FALSE)
keys
some keys, a character vector; those which do not belong to the keys of the reference map will be ignored
inplace
Boolean, whether to update the reference map or to return a new map
bydeleting
Boolean, whether to construct the submap by
deleting the keys which are not in keys
or by starting
from the empty submap and adding the entries
An omapR
object if inplace=FALSE
,
nothing otherwise.
map <- omapR$new( keys = c("a", "b", "c"), values = list(c(1, 2), c(3, 4, 5), c(6, 7)) ) map_copy <- map$copy() map$extract(c("a", "c")) map map$extract(c("a", "c"), inplace = TRUE) map map_copy$extract(c("a", "c"), bydeleting = TRUE) map_copy map_copy$extract(c("a", "c"), inplace = TRUE, bydeleting = TRUE) map_copy
has_key()
Checks whether a key exists in the reference map.
omapR$has_key(key)
key
a key (string)
A Boolean value.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$has_key("b") map$has_key("x")
nth()
Returns the n-th entry of the reference map.
omapR$nth(n, stop_if_too_large = TRUE)
n
index, a positive integer
stop_if_too_large
a Boolean value, whether to stop if n
is too large, or to use maybe
values
A list with the key and the value at index n
if
stop_if_too_large=TRUE
and n
is not too large, otherwise
a maybe
value: either this list wrapped in a 'Just' container,
or 'Nothing'.
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$nth(2) map$nth(2, stop_if_too_large = FALSE) map$nth(9, stop_if_too_large = FALSE)
insert()
Insert a new entry in the reference map.
omapR$insert(key, value, replace = FALSE)
key
a key (string)
value
a value (R object)
replace
Boolean, whether to replace the value if the key is already present
This updates the reference map and this returns a Boolean value:
if replace=FALSE
, this returns TRUE
if the value has
been inserted (i.e. the given key is new); similarly, if
replace=TRUE
, this returns TRUE
if the given key is new
(so FALSE
means that the value of the existing key has been
replaced).
map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$insert("c", c(6, 7)) # TRUE (insertion) map map$insert("a", c(8, 9)) # FALSE (no change) map map$insert("a", c(8, 9), replace = TRUE) # FALSE (replacement) map
erase()
Erase the entries of the reference map whose keys are the given ones.
omapR$erase(keys)
keys
some keys, a character vector
Nothing, this updates the map.
map <- omapR$new( keys = c("a", "b", "c"), values = list(c(1, 2), c(3, 4, 5), c(6, 7)) ) map$erase("a") map map$erase(c("b", "c")) map
merge()
Merge the reference map with another map.
omapR$merge(map, duplicated = "drop")
map
an omapR
object
duplicated
the action to perform if the reference map
and map
have some identical keys, one of
"drop"
, "join"
, or "separate"
Nothing, this updates the reference map.
map1 <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map2 <- omapR$new( keys = c("c", "d"), values = list(c(9, 8), c(7, 6)) ) map1$merge(map2) map1 # `duplicated` example #### map1 <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map1_copy1 <- map1$copy() map1_copy2 <- map1$copy() map1_copy3 <- map1$copy() map2 <- omapR$new( keys = c("a", "d"), values = list(c(9, 8), c(7, 6)) ) map1_copy1$merge(map2) map1_copy1 map1_copy2$merge(map2, duplicated = "join") map1_copy2 map1_copy3$merge(map2, duplicated = "separate") map1_copy3
copy()
Copy the reference map.
omapR$copy()
A copy of the reference map.
map <- omapR$new( c("a", "b"), list(c(1,2), c(FALSE, TRUE)) ) true_copy <- map$copy() true_copy$erase("a") map naive_copy <- map naive_copy$erase("a") map
from_just
## ------------------------------------------------ ## Method `omapR$new` ## ------------------------------------------------ omapR$new( keys = c("z", "a"), values = list(c(1, 2), c(3, 4, 5)) ) # examples with duplicated keys: omapR$new( keys = c("a", "a", "b"), values = list(c(1, 2), c(3, 4), c(5, 6)) ) omapR$new( keys = c("a", "a", "b"), values = list(c(1, 2), c(3, 4), c(5, 6)), duplicated = "join" ) omapR$new( keys = c("a", "a", "b"), values = list(c(1, 2), c(3, 4), c(5, 6)), duplicated = "separate" ) ## ------------------------------------------------ ## Method `omapR$size` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$size() ## ------------------------------------------------ ## Method `omapR$keys` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$keys() ## ------------------------------------------------ ## Method `omapR$values` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$values() ## ------------------------------------------------ ## Method `omapR$items` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$items() ## ------------------------------------------------ ## Method `omapR$toList` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$toList() ## ------------------------------------------------ ## Method `omapR$at` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$at("b") from_just(map$at("b")) map$at("x") ## ------------------------------------------------ ## Method `omapR$index` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$index("b") map$index("x") ## ------------------------------------------------ ## Method `omapR$extract` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b", "c"), values = list(c(1, 2), c(3, 4, 5), c(6, 7)) ) map_copy <- map$copy() map$extract(c("a", "c")) map map$extract(c("a", "c"), inplace = TRUE) map map_copy$extract(c("a", "c"), bydeleting = TRUE) map_copy map_copy$extract(c("a", "c"), inplace = TRUE, bydeleting = TRUE) map_copy ## ------------------------------------------------ ## Method `omapR$has_key` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$has_key("b") map$has_key("x") ## ------------------------------------------------ ## Method `omapR$nth` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$nth(2) map$nth(2, stop_if_too_large = FALSE) map$nth(9, stop_if_too_large = FALSE) ## ------------------------------------------------ ## Method `omapR$insert` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map$insert("c", c(6, 7)) # TRUE (insertion) map map$insert("a", c(8, 9)) # FALSE (no change) map map$insert("a", c(8, 9), replace = TRUE) # FALSE (replacement) map ## ------------------------------------------------ ## Method `omapR$erase` ## ------------------------------------------------ map <- omapR$new( keys = c("a", "b", "c"), values = list(c(1, 2), c(3, 4, 5), c(6, 7)) ) map$erase("a") map map$erase(c("b", "c")) map ## ------------------------------------------------ ## Method `omapR$merge` ## ------------------------------------------------ map1 <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map2 <- omapR$new( keys = c("c", "d"), values = list(c(9, 8), c(7, 6)) ) map1$merge(map2) map1 # `duplicated` example #### map1 <- omapR$new( keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5)) ) map1_copy1 <- map1$copy() map1_copy2 <- map1$copy() map1_copy3 <- map1$copy() map2 <- omapR$new( keys = c("a", "d"), values = list(c(9, 8), c(7, 6)) ) map1_copy1$merge(map2) map1_copy1 map1_copy2$merge(map2, duplicated = "join") map1_copy2 map1_copy3$merge(map2, duplicated = "separate") map1_copy3 ## ------------------------------------------------ ## Method `omapR$copy` ## ------------------------------------------------ map <- omapR$new( c("a", "b"), list(c(1,2), c(FALSE, TRUE)) ) true_copy <- map$copy() true_copy$erase("a") map naive_copy <- map naive_copy$erase("a") map
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.