Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 52
Fix missing value propagation in as_integers/doubles()#265
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5590ec92fb6201d295081d1b395a457ca82f32b8fac7635523cc57cbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -135,33 +135,44 @@ typedef r_vector<double> doubles; | ||
| } // namespace writable | ||
| template <> | ||
| inline double na() { | ||
| return NA_REAL; | ||
| } | ||
| template <> | ||
| inline bool is_na(const double& x) { | ||
| return ISNA(x); | ||
| } | ||
| // forward declarations | ||
| typedef r_vector<int> integers; | ||
| template <> | ||
| int na(); | ||
romainfrancois marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| template <> | ||
| int r_vector<int>::operator[](const R_xlen_t pos) const; | ||
romainfrancois marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| inline doubles as_doubles(sexp x) { | ||
| if (TYPEOF(x) == REALSXP) { | ||
| return as_cpp<doubles>(x); | ||
| } | ||
| else if (TYPEOF(x) == INTSXP) { | ||
| } else if (TYPEOF(x) == INTSXP) { | ||
| integers xn = as_cpp<integers>(x); | ||
| size_t len = xn.size(); | ||
| writable::doubles ret; | ||
| for (size_t i = 0; i < len; ++i) { | ||
| ret.push_back(static_cast<double>(xn[i])); | ||
romainfrancois marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| R_xlen_t len = xn.size(); | ||
romainfrancois marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| writable::doubles ret(len); | ||
| for (R_xlen_t i = 0; i < len; ++i) { | ||
| int el = xn[i]; | ||
| if (is_na(el)) { | ||
| ret[i] = na<double>(); | ||
| } else { | ||
| ret[i] = static_cast<double>(el); | ||
| } | ||
| } | ||
| return ret; | ||
| } | ||
| throw type_error(REALSXP, TYPEOF(x)); | ||
| } | ||
| template <> | ||
| inline double na() { | ||
| return NA_REAL; | ||
| } | ||
| template <> | ||
| inline bool is_na(const double& x) { | ||
| return ISNA(x); | ||
| } | ||
| } // namespace cpp11 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -145,25 +145,32 @@ inline int na() { | ||
| return NA_INTEGER; | ||
| } | ||
| // forward declaration | ||
| // forward declarations | ||
| typedef r_vector<double> doubles; | ||
| template <> | ||
| bool is_na(const double& x); | ||
romainfrancois marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| template <> | ||
| double r_vector<double>::operator[](const R_xlen_t pos) const; | ||
| inline integers as_integers(sexp x) { | ||
| if (TYPEOF(x) == INTSXP) { | ||
| return as_cpp<integers>(x); | ||
| } else if (TYPEOF(x) == REALSXP) { | ||
| doubles xn = as_cpp<doubles>(x); | ||
| size_t len = (xn.size()); | ||
| writable::integers ret = writable::integers(len); | ||
| for (size_t i = 0; i < len; ++i) { | ||
| R_xlen_t len = xn.size(); | ||
| writable::integers ret(len); | ||
| for (R_xlen_t i = 0; i < len; ++i) { | ||
| double el = xn[i]; | ||
| if (!is_convertable_without_loss_to_integer(el)) { | ||
| if (is_na(el)) { | ||
| ret[i] = na<int>(); | ||
| } else if (is_convertible_without_loss_to_integer(el)) { | ||
| ret[i] = static_cast<int>(el); | ||
| } else { | ||
| throw std::runtime_error("All elements must be integer-like"); | ||
| } | ||
| ret[i] = (static_cast<int>(el)); | ||
| } | ||
| return ret; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.