Skip to contents

Extract parts of a Container object similar to R's base extract operators on lists.

Usage

# S3 method for class 'Container'
x[...]

# S3 method for class 'Container'
x[[i]]

Arguments

x

Container object from which to extract elements.

i, ...

indices specifying elements to extract. Indices are numeric or character vectors or a list containing both.

Details

[ selects multiple values. The indices can be numeric or character or both. They can be passed as a vector or list or, for convenience, just as a comma-separated sequence (see Examples). Non-existing indices are ignored.

[[ selects a single value using a numeric or character index.

Examples

co = container(a = 1, b = 2, c = 3, d = 4)
co[1:2]
#> [a = 1, b = 2]
co[1, 4]
#> [a = 1, d = 4]
co["d", 2]
#> [d = 4, b = 2]
co[list("d", 2)]
#> [d = 4, b = 2]
co[0:10]
#> [a = 1, b = 2, c = 3, d = 4]

co = container(a = 1, b = 2)
co[[1]]
#> [1] 1
co[["a"]]
#> [1] 1
co[["x"]]
#> NULL