-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
In R, if I have a nested list, then I can access elements within it using repeated $ signs, or repeated square brackets, like so:
nested_list <- list(top = list(middle = list(tail = 42)))
nested_list$top$middle$tail
## [1] 42
nested_list[['top']]['middle']]['tail']]
## [1] 42You can also access a nested list by passing a vector to the [[ function, like so:
nested_list[[c('top', 'middle', 'tail')]]
## 42But while the first two methods work with nested RProtoBuf Messages, the last way doesn't. That is, if I pass a character vector to a Message in double square brackets, then it only returns values from the top level.
The tutorial message types don't demonstrate this problem because all of their nested Message fields are also repeated. Here is a minimal example:
syntax = proto3;
message NestedList {
.TopList top = 1;
}
message TopList {
.MiddleList middle = 1;
}
message MiddleList {
int64 tail = 1;
}The first two methods work:
readProtoFiles('nested.proto') # containing the definition above
nested_pb <- NestedList$new(top = TopList$new(middle = MiddleList$new(tail = 42)))
nested_pb$top$middle$tail
## [1] 42
nested_pb[['top']][['middle']][['tail']]
## [1] 42But the last one doesn't.
nested_pb[[c('top', 'middle', 'tail')]]
## message of type 'TopList' with 1 field setThis seems inconsistent.
MichaelChirico
Metadata
Metadata
Assignees
Labels
No labels