File tree Expand file tree Collapse file tree 2 files changed +31
-27
lines changed Expand file tree Collapse file tree 2 files changed +31
-27
lines changed Original file line number Diff line number Diff line change 7
7
8
8
#include < testthat.h>
9
9
10
+ namespace cpp11 {
11
+
12
+ inline integers as_doubles (SEXP x) {
13
+ /* if (TYPEOF(x) == REALSXP) {
14
+ return as_cpp<doubles>(x);
15
+ } else
16
+ */
17
+ if (TYPEOF (x) == INTSXP) {
18
+ integers xn = as_cpp<integers>(x);
19
+ return xn;
20
+ /*
21
+ R_xlen_t len = xn.size();
22
+ writable::doubles ret(len);
23
+ for (R_xlen_t i = 0; i < len; ++i) {
24
+ int el = xn[i];
25
+ if (el == NA_INTEGER) {
26
+ ret[i] = NA_REAL;
27
+ } else {
28
+ ret[i] = static_cast<double>(el);
29
+ }
30
+ }
31
+ return ret;
32
+ */
33
+ }
34
+
35
+ throw type_error (REALSXP, TYPEOF (x));
36
+ }
37
+
38
+ }
39
+
10
40
context (" doubles-C++" ) {
11
41
test_that (" doubles::r_vector(SEXP)" ) {
12
42
cpp11::doubles x (Rf_allocVector (REALSXP, 2 ));
@@ -379,7 +409,7 @@ context("doubles-C++") {
379
409
// cpp11::writable::integers na{NA_INTEGER};
380
410
// cpp11::sexp na();
381
411
382
- cpp11::integers na3 (Rf_ScalarInteger (NA_INTEGER));
412
+ cpp11::integers na3 (cpp11::as_doubles ( Rf_ScalarInteger (NA_INTEGER) ));
383
413
expect_true (na3.size () == 1 );
384
414
// expect_true(ISNA(na3[0]));
385
415
// expect_true(cpp11::is_na<double>(na3[0]));
Original file line number Diff line number Diff line change @@ -149,30 +149,4 @@ int na();
149
149
template <>
150
150
int r_vector<int >::operator [](const R_xlen_t pos) const ;
151
151
152
- inline integers as_doubles (SEXP x) {
153
- /* if (TYPEOF(x) == REALSXP) {
154
- return as_cpp<doubles>(x);
155
- } else
156
- */
157
- if (TYPEOF (x) == INTSXP) {
158
- integers xn = as_cpp<integers>(x);
159
- return xn;
160
- /*
161
- R_xlen_t len = xn.size();
162
- writable::doubles ret(len);
163
- for (R_xlen_t i = 0; i < len; ++i) {
164
- int el = xn[i];
165
- if (el == NA_INTEGER) {
166
- ret[i] = NA_REAL;
167
- } else {
168
- ret[i] = static_cast<double>(el);
169
- }
170
- }
171
- return ret;
172
- */
173
- }
174
-
175
- throw type_error (REALSXP, TYPEOF (x));
176
- }
177
-
178
152
} // namespace cpp11
You can’t perform that action at this time.
0 commit comments