1
- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
1
+ // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2
2
//
3
3
// misc.cpp: Rcpp R/C++ interface class library -- misc unit tests
4
4
//
5
- // Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
5
+ // Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
6
6
//
7
7
// This file is part of Rcpp.
8
8
//
20
20
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
21
22
22
#include < Rcpp.h>
23
- using namespace Rcpp ;
23
+ using namespace Rcpp ;
24
24
using namespace std ;
25
25
#include < iostream>
26
26
#include < fstream>
@@ -34,47 +34,47 @@ class simple {
34
34
};
35
35
36
36
// [[Rcpp::export]]
37
- SEXP symbol_ (){
37
+ SEXP symbol_ () {
38
38
return LogicalVector::create (
39
39
Symbol ( Rf_install (" foobar" ) ) == Rf_install (" foobar" ),
40
40
Symbol ( Rf_mkChar (" foobar" ) ) == Rf_install (" foobar" ),
41
41
Symbol ( Rf_mkString (" foobar" ) ) == Rf_install (" foobar" ),
42
42
Symbol ( " foobar" ) == Rf_install (" foobar" )
43
- ) ;
43
+ );
44
44
}
45
45
46
46
// [[Rcpp::export]]
47
- Symbol symbol_ctor (SEXP x){ return Symbol (x); }
47
+ Symbol symbol_ctor (SEXP x) { return Symbol (x); }
48
48
49
49
// [[Rcpp::export]]
50
- List Argument_ (){
50
+ List Argument_ () {
51
51
Argument x (" x" ), y (" y" );
52
52
return List::create ( x = 2 , y = 3 );
53
53
}
54
54
55
55
// [[Rcpp::export]]
56
- int Dimension_const ( SEXP ia ){
56
+ int Dimension_const ( SEXP ia ) {
57
57
simple ss (ia);
58
- return ss.nrow ();
58
+ return ss.nrow ();
59
59
}
60
60
61
61
// [[Rcpp::export]]
62
- SEXP evaluator_error (){
63
- return Rcpp_eval ( Rf_lang2 ( Rf_install (" stop" ), Rf_mkString ( " boom" ) ) ) ;
62
+ SEXP evaluator_error () {
63
+ return Rcpp_eval ( Rf_lang2 ( Rf_install (" stop" ), Rf_mkString ( " boom" ) ) );
64
64
}
65
65
66
66
// [[Rcpp::export]]
67
- SEXP evaluator_ok (SEXP x){
68
- return Rcpp_eval ( Rf_lang2 ( Rf_install (" sample" ), x ) ) ;
67
+ SEXP evaluator_ok (SEXP x) {
68
+ return Rcpp_eval ( Rf_lang2 ( Rf_install (" sample" ), x ) );
69
69
}
70
70
71
71
// [[Rcpp::export]]
72
- void exceptions_ (){
73
- throw std::range_error (" boom" ) ;
72
+ void exceptions_ () {
73
+ throw std::range_error (" boom" );
74
74
}
75
75
76
76
// [[Rcpp::export]]
77
- LogicalVector has_iterator_ ( ){
77
+ LogicalVector has_iterator_ ( ) {
78
78
return LogicalVector::create (
79
79
(bool )Rcpp::traits::has_iterator< std::vector<int > >::value,
80
80
(bool )Rcpp::traits::has_iterator< std::list<int > >::value,
@@ -87,7 +87,7 @@ LogicalVector has_iterator_( ){
87
87
}
88
88
89
89
// [[Rcpp::export]]
90
- void test_rcout (std::string tfile, std::string teststring){
90
+ void test_rcout (std::string tfile, std::string teststring) {
91
91
// define and open testfile
92
92
std::ofstream testfile (tfile.c_str ());
93
93
@@ -108,8 +108,8 @@ void test_rcout(std::string tfile, std::string teststring){
108
108
}
109
109
110
110
// [[Rcpp::export]]
111
- LogicalVector na_proxy (){
112
- CharacterVector s (" foo" ) ;
111
+ LogicalVector na_proxy () {
112
+ CharacterVector s (" foo" );
113
113
return LogicalVector::create (
114
114
NA_REAL == NA,
115
115
NA_INTEGER == NA,
@@ -130,29 +130,49 @@ LogicalVector na_proxy(){
130
130
NA == 12 ,
131
131
NA == " foo" ,
132
132
NA == s[0 ]
133
- ) ;
133
+ );
134
134
}
135
135
136
136
// [[Rcpp::export]]
137
- StretchyList stretchy_list (){
138
- StretchyList out ;
139
- out.push_back ( 1 ) ;
140
- out.push_front ( " foo" ) ;
141
- out.push_back ( 3.2 ) ;
137
+ StretchyList stretchy_list () {
138
+ StretchyList out;
139
+ out.push_back ( 1 );
140
+ out.push_front ( " foo" );
141
+ out.push_back ( 3.2 );
142
142
return out;
143
143
}
144
144
145
145
// [[Rcpp::export]]
146
- StretchyList named_stretchy_list (){
147
- StretchyList out ;
148
- out.push_back ( _[" b" ] = 1 ) ;
149
- out.push_front ( _[" a" ] = " foo" ) ;
150
- out.push_back ( _[" c" ] = 3.2 ) ;
146
+ StretchyList named_stretchy_list () {
147
+ StretchyList out;
148
+ out.push_back ( _[" b" ] = 1 );
149
+ out.push_front ( _[" a" ] = " foo" );
150
+ out.push_back ( _[" c" ] = 3.2 );
151
151
return out;
152
152
}
153
153
154
154
// [[Rcpp::export]]
155
- void test_stop_variadic (){
156
- stop ( " %s %d" , " foo" , 3 ) ;
155
+ void test_stop_variadic () {
156
+ stop ( " %s %d" , " foo" , 3 );
157
+ }
158
+
159
+ // [[Rcpp::export]]
160
+ bool testNullableForNull (Nullable N) {
161
+ return N.isNull ();
162
+ }
163
+
164
+ // [[Rcpp::export]]
165
+ bool testNullableForNotNull (Nullable N) {
166
+ return N.isNotNull ();
167
+ }
168
+
169
+ // [[Rcpp::export]]
170
+ SEXP testNullableOperator (Nullable N) {
171
+ return N;
172
+ }
173
+
174
+ // [[Rcpp::export]]
175
+ SEXP testNullableGet (Nullable N) {
176
+ return N.get ();
157
177
}
158
178
0 commit comments