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.
Arguments
- x
A
ts_treeobject.- i
A list with selection expressions, see
ts_tree_select()for details.- value
An R expression to serialize or
ts_tree_deleted().
Details
The following two expressions are equivalent:
tree <- ts_tree_select(tree, <selectors>) |> ts_tree_update(value)
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"}