eddelbuettel commented on issue #67:
URL: https://github.com/apache/arrow-nanoarrow/issues/67#issuecomment-1337497650
Thanks so much:
```r
> rl <- rcppnanoarrow::createArray()
> rl
$schema
<pointer: 0x55aa74b08ee0>
attr(,"class")
[1] "arch_schema"
$array_data
<pointer: 0x55aa76febc90>
attr(,"class")
[1] "arch_array_data"
attr(,"class")
[1] "arch_array"
> tibble::as_tibble(arch::from_arch_array(rl, arrow::RecordBatch))
# A tibble: 3 × 2
intCol dblCol
<int> <dbl>
1 21 21.1
2 42 42.2
3 63 63.3
>
```
'Repaired' code below.
<details>
```c++
//' @export
// [[Rcpp::export]]
Rcpp::List createArray() {
const int ncol = 2;
const int nrow = 3;
auto schemaxp = Rcpp::XPtr<struct ArrowSchema>(new struct ArrowSchema);
schemaxp.attr("class") = "arch_schema";
auto schema = schemaxp.get();
ArrowSchemaInit(schema, NANOARROW_TYPE_STRUCT);
ArrowSchemaAllocateChildren(schema, ncol);
auto arrayxp = Rcpp::XPtr<struct ArrowArray>(new struct ArrowArray);
arrayxp.attr("class") = "arch_array_data";
auto array = arrayxp.get();
ArrowArrayInit(array, NANOARROW_TYPE_STRUCT);
ArrowArrayAllocateChildren(array, ncol);
array->length = nrow;
array->null_count = -1;
// ...fill in schema.children and array.children
ArrowSchemaInit(schema->children[0], NANOARROW_TYPE_INT32);
ArrowSchemaSetName(schema->children[0], "intCol");
ArrowArrayInit(array->children[0], NANOARROW_TYPE_INT32);
ArrowArrayStartAppending(array->children[0]);
ArrowArrayAppendInt(array->children[0], 21);
ArrowArrayAppendInt(array->children[0], 42);
ArrowArrayAppendInt(array->children[0], 63);
ArrowArrayFinishBuilding(array->children[0], nullptr);
ArrowSchemaInit(schema->children[1], NANOARROW_TYPE_DOUBLE);
ArrowSchemaSetName(schema->children[1], "dblCol");
ArrowArrayInit(array->children[1], NANOARROW_TYPE_DOUBLE);
ArrowArrayStartAppending(array->children[1]);
ArrowArrayAppendDouble(array->children[1], 21.1);
ArrowArrayAppendDouble(array->children[1], 42.2);
ArrowArrayAppendDouble(array->children[1], 63.3);
ArrowArrayFinishBuilding(array->children[1], nullptr);
Rcpp::List as = Rcpp::List::create(Rcpp::Named("schema") = schemaxp,
Rcpp::Named("array_data") = arrayxp);
//as.attr("class") = "nanoarrow_array";
as.attr("class") = "arch_array";
return as;
}
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]