-
Notifications
You must be signed in to change notification settings - Fork 51
Feature converter ints doubles #201
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
Feature converter ints doubles #201
Conversation
I think you are right, |
Looks like you have a blank newline that is causing the format_check job to fail https://github.com/r-lib/cpp11/pull/201/checks?check_run_id=3024080555#step:5:11. FWIW in RStudio you can enable showing whitespace characters with Tools -> Global Options -> Code -> Display, check "Show whitespace characters". Which could help spot these more easily. |
Okay I'm going to make those changes to function names. Any insights you might have on the ubuntu 3.4 error? I can't really tell where or why it's occurring. |
I was able to reproduce it locally with R 3.4, it seems like an issue related to Switching the errors to throw regular C++ exceptions instead fixes the test failures. I think it might be worth changing all the uses of |
@@ -148,8 +148,7 @@ inline doubles as_double(sexp x) { | |||
return ret; | |||
} | |||
|
|||
// else | |||
stop("Expected a numeric vector for"); | |||
throw type_error(INTSXP, TYPEOF(x)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cpp11 defines a type_error
class to generate a more informative error message for type issues, so we can use that here.
cpp11/inst/include/cpp11/r_vector.hpp
Lines 26 to 39 in 23ae34f
class type_error : public std::exception { | |
public: | |
type_error(int expected, int actual) : expected_(expected), actual_(actual) {} | |
virtual const char* what() const noexcept { | |
snprintf(str_, 64, "Invalid input type, expected '%s' actual '%s'", | |
Rf_type2char(expected_), Rf_type2char(actual_)); | |
return str_; | |
} | |
private: | |
int expected_; | |
int actual_; | |
mutable char str_[64]; | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay awesome thank you!
Okay I will make a new issue to change instances of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, feel free to merge it once you are ready.
Might better to name them
as_doubles()
andas_integers()
to differentiate from scalardouble
andint
?? When I first was making it that sounded odd to me but now I'm not so convinced.fixes #46