File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,13 @@ namespace Rcpp {
91
91
return m_sexp;
92
92
}
93
93
94
+ /* *
95
+ * Boolean test for usability as a T
96
+ */
97
+ inline bool isUsable () const {
98
+ return m_set && !Rf_isNull (m_sexp);
99
+ }
100
+
94
101
/* *
95
102
* Boolean test for NULL
96
103
*
Original file line number Diff line number Diff line change @@ -207,3 +207,12 @@ NumericMatrix testNullableAs(Nullable<NumericMatrix>& M) {
207
207
NumericMatrix testNullableClone (const Nullable<NumericMatrix>& M) {
208
208
return M.clone ();
209
209
}
210
+
211
+ // [[Rcpp::export]]
212
+ SEXP testNullableIsUsable (const Nullable<NumericMatrix>& M) {
213
+ if (M.isUsable ()) {
214
+ return M.clone ();
215
+ } else {
216
+ return R_NilValue;
217
+ }
218
+ }
Original file line number Diff line number Diff line change @@ -195,4 +195,13 @@ if (.runThisTest) {
195
195
M <- matrix (1 : 4 , 2 , 2 )
196
196
checkEquals( testNullableClone(M ), M )
197
197
}
198
+
199
+ test.NullableIsUsableTrue <- function () {
200
+ M <- matrix (1 : 4 , 2 , 2 )
201
+ checkEquals( testNullableIsUsable(M ), M )
202
+ }
203
+
204
+ test.NullableIsUsableFalse <- function () {
205
+ checkTrue(is.null(testNullableIsUsable(NULL )))
206
+ }
198
207
}
You can’t perform that action at this time.
0 commit comments