Learn R Programming

datastructures (version 0.2.9)

at: Access elements from an object

Description

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.

Usage

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)

Arguments

obj

object to extract values from

x

the set of keys to match the values

which

choose either values if the values should get returned

...

other arguments or keys if the keys should get returned

Value

returns extracted keys or values from obj

Details

# 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/>.

Examples

Run this code
# NOT RUN {
# 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]

# 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))
at(b_map, c(1L, 3L), which="values")
at(b_map, c("a", "c"), which="keys")

# access values from a multimap
m_map <- multimap("integer")
m_map[c(seq(5), seq(5))] <- letters[seq(10)]
at(m_map, 1L)

# }

Run the code above in your browser using DataLab