| umapR | R Documentation |
A map is given by keys and values. The keys must be some strings, the values can be any R objects.
new()Creates a new umapR object.
umapR$new(keys, values, duplicated = "drop", checks = TRUE)
keysthe keys, a character vector without NA value
valuesthe values, a list of R objects; keys and
values must have the same length
duplicatedthe action to perform for duplicated keys, one of
"drop", "join", or "separate"
checksBoolean, whether to check keys and values
A umapR object.
umapR$new(
keys = c("a", "b"),
values = list(c(1, 2), c(3, 4, 5))
)
# examples with duplicated keys:
umapR$new(
keys = c("a", "a", "b"),
values = list(c(1, 2), c(3, 4), c(5, 6))
)
umapR$new(
keys = c("a", "a", "b"),
values = list(c(1, 2), c(3, 4), c(5, 6)),
duplicated = "join"
)
umapR$new(
keys = c("a", "a", "b"),
values = list(c(1, 2), c(3, 4), c(5, 6)),
duplicated = "separate"
)
print()Show instance of a umapR object.
umapR$print(...)
...ignored
size()Size of the map.
umapR$size()
An integer, the number of entries.
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$size()
keys()Get all keys.
umapR$keys()
The keys, a character vector.
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$keys()
values()Get all values.
umapR$values()
The values, a list of R objects.
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$values()
items()Get all entries.
umapR$items()
The entries in a dataframe.
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$items()
toList()Converts the map to a named list.
umapR$toList()
A named list.
map <- umapR$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.
umapR$at(key)
keya 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 <- umapR$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")
at_unsafe()Returns the value corresponding to the given key.
umapR$at_unsafe(key)
keya key (string)
The value corresponding to the given key if this key is found, otherwise an error.
extract()Extract a submap from the reference map.
umapR$extract(keys, inplace = FALSE, bydeleting = FALSE)
keyssome keys, a character vector; those which do not belong to the keys of the reference map will be ignored
inplaceBoolean, whether to update the reference map or to return a new map
bydeletingBoolean, 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
Invisibly: a new umapR object if inplace=FALSE,
otherwise the updated reference map.
map <- umapR$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.
umapR$has_key(key)
keya key (string)
A Boolean value.
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$has_key("b")
map$has_key("x")
insert()Insert a new entry in the reference map.
umapR$insert(key, value, replace = FALSE)
keya key (string)
valuea value (R object)
replaceBoolean, whether to replace the value if the key is already present
This updates the reference map and this returns it invisibly. Moreover, a message is printed, describing the update (insertion of a new key, replacement of value, or no change).
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$insert("c", c(6, 7)) # insertion
map
map$insert("a", c(8, 9)) # no change
map
map$insert("a", c(8, 9), replace = TRUE) # replacement
map
erase()Erase the entries of the reference map corresponding to the given keys.
umapR$erase(keys)
keyssome keys, a character vector
The updated reference map, invisibly.
map <- umapR$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.
umapR$merge(map, duplicated = "drop")
mapa umapR object
duplicatedthe action to perform if the reference map
and map have some identical keys, one of
"drop", "join", or "separate"
The updated reference map, invisibly.
map1 <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map2 <- umapR$new(
keys = c("c", "d"), values = list(c(9, 8), c(7, 6))
)
map1$merge(map2)
map1
# `duplicated` example ####
map1 <- umapR$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 <- umapR$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.
umapR$copy()
A copy of the reference map.
map <- umapR$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 `umapR$new`
## ------------------------------------------------
umapR$new(
keys = c("a", "b"),
values = list(c(1, 2), c(3, 4, 5))
)
# examples with duplicated keys:
umapR$new(
keys = c("a", "a", "b"),
values = list(c(1, 2), c(3, 4), c(5, 6))
)
umapR$new(
keys = c("a", "a", "b"),
values = list(c(1, 2), c(3, 4), c(5, 6)),
duplicated = "join"
)
umapR$new(
keys = c("a", "a", "b"),
values = list(c(1, 2), c(3, 4), c(5, 6)),
duplicated = "separate"
)
## ------------------------------------------------
## Method `umapR$size`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$size()
## ------------------------------------------------
## Method `umapR$keys`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$keys()
## ------------------------------------------------
## Method `umapR$values`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$values()
## ------------------------------------------------
## Method `umapR$items`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$items()
## ------------------------------------------------
## Method `umapR$toList`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$toList()
## ------------------------------------------------
## Method `umapR$at`
## ------------------------------------------------
map <- umapR$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 `umapR$extract`
## ------------------------------------------------
map <- umapR$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 `umapR$has_key`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$has_key("b")
map$has_key("x")
## ------------------------------------------------
## Method `umapR$insert`
## ------------------------------------------------
map <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map$insert("c", c(6, 7)) # insertion
map
map$insert("a", c(8, 9)) # no change
map
map$insert("a", c(8, 9), replace = TRUE) # replacement
map
## ------------------------------------------------
## Method `umapR$erase`
## ------------------------------------------------
map <- umapR$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 `umapR$merge`
## ------------------------------------------------
map1 <- umapR$new(
keys = c("a", "b"), values = list(c(1, 2), c(3, 4, 5))
)
map2 <- umapR$new(
keys = c("c", "d"), values = list(c(9, 8), c(7, 6))
)
map1$merge(map2)
map1
# `duplicated` example ####
map1 <- umapR$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 <- umapR$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 `umapR$copy`
## ------------------------------------------------
map <- umapR$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.