I have tested the below example with RProtobuf 0.4.9 on R version 3.4.1 (x86_64-pc-linux-gnu).
The fetch method disregards the provided index for repeated message types:
> p <- new(tutorial.Person, name = "John", id = 1) > p$add("phone", new(tutorial.Person.PhoneNumber, number = "one")) > p$add("phone", new(tutorial.Person.PhoneNumber, number = "two")) > p$add("phone", new(tutorial.Person.PhoneNumber, number = "three")) > for (i in 1:3) { cat(p$fetch("phone", i)[[1]]$toString()) } number: "one" number: "one" number: "one" # expected to see: one, two, three
I believe the issue is with the get_field_values
code in wrapper_Message.cpp. The code uses raw loop variable i
instead of index[i]
for repeated messages and groups:
res[i] = S4_Message(CLONE(&ref->GetRepeatedMessage(*message, field_desc, i)));
Hence the fix should be trivial:
res[i] = S4_Message(CLONE(&ref->GetRepeatedMessage(*message, field_desc, index[i])));
Please also note that a reasonable workaround for this issue is to iterate through the repeated messages without using the fetch method:
> p <- new(tutorial.Person, name = "John", id = 1) > p$add("phone", new(tutorial.Person.PhoneNumber, number = "one")) > p$add("phone", new(tutorial.Person.PhoneNumber, number = "two")) > p$add("phone", new(tutorial.Person.PhoneNumber, number = "three")) > for (telephone in p$phone) { cat(telephone$toString()) } number: "one" number: "two" number: "three"
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4