-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Adding Rcpp signature attribute #1184
Conversation
ddb3554
to
0ff6b77
Compare
Some comments:
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export( rng = false, signature = {x = list("{A}", "B"), verbose=FALSE} )]]
int test_inline(List x, bool verbose=true) {
Rcout << "The verbose paramter is set to: ";
Rcout << verbose << std::endl;
if(x.size() > 0) {
CharacterVector first_element = x[0];
Rcout << "The first element of list x is: ";
Rcout << first_element << std::endl;
}
return x.size();
}')
test_inline()
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export( rng = false, signature = {x = list("{A}", "B")} )]]
int test_inline(List x, bool verbose=true) {
Rcout << "The verbose paramter is set to: ";
Rcout << verbose << std::endl;
if(x.size() > 0) {
CharacterVector first_element = x[0];
Rcout << "The first element of list x is: ";
Rcout << first_element << std::endl;
}
return x.size();
}')
test_inline()
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export( rng = false, signature = {x = list("{A}", "B"), verbose=FALSE )]]
int test_inline(List x, bool verbose) {
Rcout << "The verbose paramter is set to: ";
Rcout << verbose << std::endl;
if(x.size() > 0) {
CharacterVector first_element = x[0];
Rcout << "The first element of list x is: ";
Rcout << first_element << std::endl;
}
return x.size();
}')
test_inline()
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export( rng = false, signature = {x = list("A", "B"), verbose=FALSE )]]
int test_inline(List x, bool verbose) {
Rcout << "The verbose paramter is set to: ";
Rcout << verbose << std::endl;
if(x.size() > 0) {
CharacterVector first_element = x[0];
Rcout << "The first element of list x is: ";
Rcout << first_element << std::endl;
}
return x.size();
}')
test_inline()
|
How about something like this? (prototyping in R, but could be converted to C++)
This checks that all arguments required by the Rcpp function exist in the R signature (so at least it won't segfault in your second example). Broader question: how much do you need to protect against user error / typos / mistakes? |
My two cents. Avoiding segfaults is a must have. :) Then, |
So as expected, the reverse dependency check did not reveal new issues caused by this PR. It is a new code path, it alters an existing access pattern that already is extremely lightly to not all used in standard tests. So no issue there. But @Enchufa2 makes good points above. We should probably add a bit more unit testing to this before going any further. @Travers, do you think you can make a few tests operational on this? |
|
* add signature attribute * roll minor version in config.h (to match DESCRIPTION) * disable codecov comments on PRs, lower threshold, increase delta * add checks for proper syntax of signature attribute * add checks for proper syntax of signature attribute * adding tinytest for rcpp attributes * add checks for proper syntax of signature attribute * add checks for proper syntax of signature attribute * adding tinytest for rcpp attributes * cleanup and rebase for signature attribute pr * cleanup and rebase for signature attribute pr * cleanup and rebase for signature attribute pr * cleanup and rebase for signature attribute pr Co-authored-by: Dirk Eddelbuettel <edd@debian.org>
@jjallaire when you have a few moments over a fresh cup of joe for this PR some time this week we would love to hear your input. With a supplementary PR merged into this PR we should be in (generally) good shape. |
Hi @traversc any chance you could comment on the points by @kevinushey ? |
Sorry, I didn't think those questions were directed to me. The first comment on checking The question on The question on error proagation: I believe an error from Let me know what you guys decide and I can write another pull request. |
As for errors: we |
I understand the throwing part, but I'm not sure of the type of error thrown by The following works:
But is this right? I don't understand how an R error gets converted into a |
My question re: errors was just to confirm that errors (e.g. from invalid signatures) are appropriately handled; it sounds like you've confirmed that's the case in testing. (If that's indeed the case then I don't think any changes are necessary) |
Looks like we're getting really close. @traversc could you maybe add one more tiny PR cleaning up the nudges above? |
No issue arose in the reverse-depends check. So ... I guess we're all kewl with this now? @kevinushey @jjallaire @Enchufa2 ? Any final glances ? |
LGTM! |
👍 |
In it goes --thanks for this, @traversc, and for your patience in dealing with Team Rcpp. |
This PR extends / revisits #1183 which got close for technical reasons. See #1182 for discussion motivating it.
Checklist
R CMD check
still passes all tests