OpsReplace {container}R Documentation

Replace Parts of a Container

Description

Replace parts of a Container object similar to R's base replace operators on lists.

Usage

## S3 replacement method for class 'Container'
x[i] <- value

## S3 replacement method for class 'Container'
x[[i]] <- value

## S3 replacement method for class 'Container'
x$name <- value

Arguments

x

Container object in which to replace elements.

i

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

value

the replacing value of ANY type

name

character string (possibly backtick quoted)

Details

⁠[<-⁠ replaces multiple values. The indices can be numeric or character or both. They can be passed as a vector or list. Values can be added by 'replacing' at new indices, which only works for character indices.

⁠[[<-⁠ replaces a single value at a given numeric or character index. Instead of an index, it is also possible to replace certain elements by passing the element in curly braces (see Examples), that is, the object is searched for the element and then the element is replaced by the value.

⁠$<-⁠ replaces a single element at a given name.

Examples

co = container(a = 1, b = "bar")
(co[1:2] <- 1:2)

try({
co[3] <- 3 # index out of range
})
(co[list(1, "b")] <- 3:4)   # mixed numeric/character index

co = container(a = 1, b = 2)
co[[1]] <- 9
co[["b"]] <- 8
co[["x"]] <- 7
co$z <- 99
print(co)

# Replace 8 by 0
co[[{8}]] <- 0
print(co)


co = container(a = 1, b = "bar")
co$f <- 3
co$b <- 2
co


[Package container version 1.0.4 Index]