Learn R Programming

container (version 0.3.0)

dictS3replace: Extract or replace Dict values

Description

Access and assignment operators for Dict objects.

Usage

# S3 method for Dict
[[(dic, key, add = FALSE) <- value

# S3 method for Dict [(dic, key) <- value

# S3 method for Dict [[(dic, key)

# S3 method for Dict [(dic, key, default = NULL)

Arguments

dic

Dict object

key

(character) the key

add

(logical) if TRUE, value is added if not yet in dict. If FALSE and value not yet in dict, an error is signaled.

value

the value associated with the key

default

the default value

Value

updated Dict object

value at key

element found at key, or default if not found.

Details

dic[key] <- value: If key not yet in dic, insert value at key, otherwise raise an error.

dic[key]: If key in dic, return value, else throw key-error.

dic[key, default=NULL]: Return the value for key if key is in dic, else default.