我正在搞tidyjson
(最新來自github,由Jeremy Stanley出版)。我想排序自動搜索並提取嵌套數組。以下示例提供了我想要的輸出。將字符變量傳遞給函數R(Tidyjson)
'{"name": {"first": "bob", "last": "jones"}, "age": 32}' %>%
enter_object("name") %>%
gather_keys %>%
append_values_string
'{"name": {"first": "bob", "last": "jones"}, "age": 32}' %>%
enter_object(name) %>%
gather_keys %>%
append_values_string
這些都給出相同的輸出:
# A tbl_json: 2 x 3 tibble with a "JSON" attribute
`attr(., "JSON")` document.id key string
<chr> <int> <chr> <chr>
1 "bob" 1 first bob
2 "jones" 1 last jones
但是,如果我宣佈前一個字符變量,並沿着它無法通過。
object_name <- "name"
'{"name": {"first": "bob", "last": "jones"}, "age": 32}' %>%
enter_object(list(name="name")) %>%
gather_keys %>%
append_values_string
Error: Path components must be single names or character strings
任何想法爲什麼會發生這種情況?