-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimal cbind sugar function #407
Comments
Nice! And as a real quick reply: could we not 'trick it' by macro expansion to provide 2, 3, 4, 5, .... arguments? I can live without dimnames, and support for data.frame objects... |
I get a compile error + a segfault in the following example: // [[Rcpp::export]]
NumericMatrix my_cbind(NumericVector x, NumericVector y) {
return cbind(x, y);
}
/*** R
my_cbind(1, 2)
*/
|
Yikes - I guess g++ didn't catch that for some reason. I'll take this back to the drawing board for now. |
Compiling with clang++, I ran into the above issue. Removing the |
Regarding the macro suggestion, I was able to work something out with |
That comes close. We used to keep the scripts in sync with the generated code, but that fell to the side at some point. I'd rather keep it sync'ed but I wasn't the only one committing at the time ... Scripts are in this repo and you should get an idea of which created what. By the way, I quite like this. Thanks for doing it. |
One of the really unfortunate issues with |
Doh. I forgot about that--the reason we do not use |
That is unfortunate, but understandable. I'll see what else I can come up with. |
I had some free time this past week and was able to take another look at this. I worked out a different approach to allowing for a variable number of arguments by overloading By and large, this implementation seems to be working correctly. I still have to iron out a couple of known issues -- mainly the current interface not accepting |
💯 |
Regarding the commit referenced above, I was able fix most of the issues noted in my previous comment: // devtools::install_github("nathan-russell/Rcpp")
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::CharacterMatrix err1(Rcpp::CharacterMatrix x, std::string y) {
return Rcpp::cbind(x, y);
}
// [[Rcpp::export]]
Rcpp::CharacterMatrix err2(Rcpp::CharacterMatrix x, Rcpp::String y) {
return Rcpp::cbind(x, y);
}
// devtools::install_github("RcppCore/Rcpp") I suspect this will take a bit longer to work out given the nature of R strings. |
Strings are officially 'difficult' with encoding issues, char vs wide char, and what not. I think the dplyr team learned the meaning of the blues over that too. More seriously, don't let the perfect be the enemy of the (more than just reasonably) good. If you have something with numbers that is clean I'd take it. Comments, anyone? |
Okay that sounds good to me. I'll submit a PR shortly for easier code review. |
Thanks for staying on top of this and closing it. |
I've been working on an implementation for a
cbind
sugar function, but since my current design lacks some of the features ofbase::cbind
I'm not sure it's on par with the rest of theRcpp::sugar
functions, and was hoping to get some feedback and / or suggestions for improving it. The source can be viewed in this gist (I didn't want to dump 300 lines of code into this ticket), but to summarize the pros and cons:Good:
Matrix
/Matrix
,Matrix
/Vector
,Matrix
/scalar
,Vector
/Vector
,Vector
/Matrix
,Vector
/scalar
,scalar
/Matrix
,scalar
/Vector
argument pairsVector
s)Shortcomings:
base::cbind
's...
argument (I'm not sure how to address this without dipping into C++11, or if it's even possible in C++98) , although nested calls seem to work correctly (e.g.cbind(cbind(cbind(arg1, arg2), arg3), arg4)
)dimnames
attribute is not preservedDataFrame
sFrom the testing I've done so far, the supported features above correctly mimic the behavior of
base::cbind
, but I'm not sure what the general consensus is on including less-than-comprehensive sugar functions in the package. Is it worthwhile to have a version ofcbind
with limited functionality? And of course, I'd be more than happy to look into any suggestions for improving this.The text was updated successfully, but these errors were encountered: