Walks a key path and returns default if any level is missing or NULL,
rather than erroring. Parsed JSON is deeply nested and frequently missing
branches, so this is the difference between a client that reads cleanly and
one buried in if (!is.null(...)).
Usage
pluck_at(x, ..., default = NULL)
Arguments
- x
A list, usually a parsed JSON body.
- ...
Keys to follow, outermost first.
- default
Returned when any level of the path is missing or NULL.
Value
The value at the end of the path, or default.
Examples
body <- list(data = list(gene = list(symbol = "BRCA1")))
pluck_at(body, "data", "gene", "symbol")
#> [1] "BRCA1"
pluck_at(body, "data", "variant", "id", default = NA_character_)
#> [1] NA