R/methods_at.R
, R/ds_map_bimap.R
, R/ds_map_unordered.R
at-methods.Rd
Extracts a set of <key, value> pairs. For hashmaps
mappings from
$$f: keys -> values,$$
exist so argument which
is per default values
(since these
are going to be retrieved). For bimaps
also
$$f: values -> keys,$$
mappings exist, such that which
can also be keys
if the keys
from the object should be retrieved.
at(obj, x, which = c("values", "keys"), ...) # S4 method for bimap,vector,character at(obj, x, which = c("values", "keys")) # S4 method for bimap,vector,missing at(obj, x) # S4 method for unordered_map,vector,missing at(obj, x)
obj | object to extract values from |
---|---|
x | the set of keys to match the values |
which | choose either |
... | other arguments
or |
returns extracted keys or values from obj
# datastructures: Implementation of core datastructures for R. # # Copyright (C) Simon Dirmeier # # This file is part of datastructures. # # datastructures is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # datastructures is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with datastructures. If not, see <http://www.gnu.org/licenses/>.
# access values from a hashmap h_map <- hashmap("integer") h_map[seq(2)] <- list(data.frame(a=rexp(3), b=rnorm(3)), environment()) h_map[1L]#> [[1]] #> a b #> 1 2.3714437 -1.00599730 #> 2 0.6686661 -0.08433889 #> 3 0.2015218 -0.55406480 #># access values or keys from a bimap b_map <- bimap("integer", "character") b_map[seq(5)] <- letters[seq(5)] at(b_map, c(1L, 3L))#> [1] "a" "c"#> [1] "a" "c"#> [1] 1 3# access values from a multimap m_map <- multimap("integer") m_map[c(seq(5), seq(5))] <- letters[seq(10)] at(m_map, 1L)#> [[1]] #> [1] "f" #> #> [[2]] #> [1] "a" #>