Skip to content

The [[<- operator works similarly to the combination of ts_tree_select() and ts_tree_update(), (and also to the replacement function ts_tree_select<-()), but it might be more readable.

Usage

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

Arguments

x

A ts_tree object.

i

A list with selection expressions, see ts_tree_select() for details.

value

An R expression to serialize or ts_tree_deleted().

Value

The modified ts_tree object.

Details

The following two expressions are equivalent:

 

tree <- ts_tree_select(tree, <selectors>) |> ts_tree_update(value)
and

 

tree[[list(<selectors>)]] <- value

Examples

# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc('{"a": 13, "b": [1, 2, 3], "c": "x"}')

tree
#> # jsonc (1 line)
#> 1 | {"a": 13, "b": [1, 2, 3], "c": "x"}

tree[[list("a")]] <- 42
tree[[list("b", -1)]] <- ts_tree_deleted()

tree
#> # jsonc (1 line)
#> 1 | {"a": 42, "b": [1, 2], "c": "x"}