Closed pepijn-devries closed 7 months ago
Never mind. The problem was that I was using the generic return type sexp
. When I changed it to writable::list
it worked
library(cpp11)
cpp_function("
writable::list test() {
writable::list result((R_xlen_t)0);
for (int i = 0; i < 10; i++) {
writable::integers x((R_xlen_t)0);
for (int j = 0; j < i; j++) {
x.push_back(j);
}
result.push_back(x);
}
return result;
}
")
test()
When adding
integers
of increasing length to alist
, usingpush_back
, the elements of the list becomeR_NilValue
. Is this a bug in cpp11, or am I doing something wrong?Created on 2023-11-27 with reprex v2.0.2