Skip to content

Commit c6a14ab

Browse files
move as_doubles to test file ???
1 parent 7082f36 commit c6a14ab

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

cpp11test/src/test-doubles.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@
77

88
#include <testthat.h>
99

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+
1040
context("doubles-C++") {
1141
test_that("doubles::r_vector(SEXP)") {
1242
cpp11::doubles x(Rf_allocVector(REALSXP, 2));
@@ -379,7 +409,7 @@ context("doubles-C++") {
379409
// cpp11::writable::integers na{NA_INTEGER};
380410
// cpp11::sexp na();
381411

382-
cpp11::integers na3(Rf_ScalarInteger(NA_INTEGER));
412+
cpp11::integers na3(cpp11::as_doubles(Rf_ScalarInteger(NA_INTEGER)));
383413
expect_true(na3.size() == 1);
384414
// expect_true(ISNA(na3[0]));
385415
// expect_true(cpp11::is_na<double>(na3[0]));

inst/include/cpp11/doubles.hpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,4 @@ int na();
149149
template <>
150150
int r_vector<int>::operator[](const R_xlen_t pos) const;
151151

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-
178152
} // namespace cpp11

0 commit comments

Comments
 (0)