Comments (6)
I don't really see what this extra indirection buys you though, it isn't actually a constant reference to an R object, it is a constant reference to a intermediate object. You might as well just use a copy by value object directly rather than a reference.
e.g. in Rcpp const int&
is basically equivalent to
my_fun(const int&);
SEXP x_sxp;
const int x_wrap = INTEGER(x_sxp)[0];
my_fun(x_wrap);
But the semantics of that in terms of behavior and number of copies are identical to
my_fun(const int);
SEXP x_sxp;
my_fun(INTEGER(x_sxp)[0]);
As far as extensions go you should be able to define custom as_cpp()
overloads. If you define them in arrow_types.h
they will be added to the generated code.
from cpp11.
Yeah, this is more about the const-ness of the function the package developer is writing, e.g.
// [[arrow::export]]
Rcpp::List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table,
bool use_threads) {
int64_t nc = table->num_columns();
int64_t nr = table->num_rows();
Rcpp::CharacterVector names(nc);
std::vector<std::shared_ptr<arrow::r::Converter>> converters(nc);
for (int64_t i = 0; i < nc; i++) {
converters[i] =
arrow::r::Converter::Make(table->column(i)->type(), table->column(i)->chunks());
names[i] = Rcpp::String(table->field(i)->name(), CE_UTF8);
}
if (use_threads) {
return arrow::r::to_dataframe_parallel(nr, nc, names, converters);
} else {
return arrow::r::to_dataframe_serial(nr, nc, names, converters);
}
}
having table
as a const std::shared_ptr<arrow::Table>&
here prevents me from messing with it inside the function. I can do a as_cpp<shared_ptr<T>>(SEXP from)
I guess with some enable_if
but I don't think I could do a as_cpp<const std::shared_ptr<T>&>()
.
from cpp11.
You can do as_cpp<const std::shared_ptr<T>>()
though, e.g. without the reference.
from cpp11.
Fair enough. That would look different from the rest of the code base, but that's fine I guess.
Now, arrow also has a few functions that take a const std::unique_ptr<T>&
, e.g.
// [[arrow::export]]
int64_t ipc___Message__body_length(const std::unique_ptr<arrow::ipc::Message>& message) {
return message->body_length();
}
The way this is organized is that the R6 object eventually holds an external pointer to the unique_ptr
, we create the unique_ptr<>
once when the XPtr
is created and the XPtr
is responsible for deletion, but still we can use const std::unique_ptr<arrow::ipc::Message>& message
in the parameters without having to copy, which is by design forbidden.
from cpp11.
Maybe this is "too magical" and arrow can step back to using something more explicit that would be copiable, e.g.
// [[arrow::export]]
int64_t ipc___Message__body_length(arrow::r::R6<std::unique_ptr<arrow::ipc::Message>> message) {
return message->body_length();
}
from cpp11.
Closing this, arrow
has to do do its own code generation anyway because of availability or not of the shared library.
from cpp11.
Related Issues (20)
- `package("<pkg>")` error if package namespace not found
- Release cpp11 0.4.4 HOT 4
- tests in 'tests/testthat.R' failed HOT 2
- Examples
- `unwind_protect()` global option is falsely assumed to be immutable HOT 1
- Nested `unwind_protect()` calls going through R can be very dangerous
- Release cpp11 0.4.6
- Issues with cpp11 0.4.4 changes to the preserve list structure
- std::max_element fails on writable vectors
- Writable vectors could allow `T&` conversion HOT 1
- Add `complexes` and `r_complex` support
- Memory leak with reassigning `cpp11::writable::list`, and maybe others HOT 1
- Importing more headers than required? [How to write a vector or integer's coordinates in R's cpp11?]
- Creating a growing `list` with cpp11 results in elements with `R_NilValue`s at one point HOT 1
- Release cpp11 0.4.7
- C++ ODR violated when using `testthat` HOT 2
- `SEXP` vs. `void *` HOT 1
- Error with list of vectors/matrices HOT 1
- `BEGIN_CPP11 + END_CPP11` -> using `Rf_errorcall(call, ...)` HOT 1
- Found non-API calls to R: `SETLENGTH`, `SET_TRUELENGTH` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpp11.