-
-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathmodref.R
More file actions
58 lines (41 loc) · 1.06 KB
/
modref.R
File metadata and controls
58 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require( Rcpp )
if(!require( inline ))
q("no")
inc <- '
class World {
public:
World() : foo(1), msg("hello") {}
void set(std::string msg_) { this->msg = msg_; }
std::string greet() { return msg; }
int foo ;
double bar ;
private:
std::string msg;
};
void clearWorld( World* w ){
w->set( "" );
}
RCPP_MODULE(yada){
using namespace Rcpp ;
class_<World>( "World" )
.method( "greet", &World::greet )
.method( "set", &World::set )
.method( "clear", &clearWorld )
.field( "foo", &World::foo )
.field_readonly( "bar", &World::bar )
;
}
'
fx <- inline::cxxfunction( signature(), "" , include = inc, plugin = "Rcpp" )
mod <- Module( "yada", getDynLib(fx) )
World <- mod$World
ww = new(World)
wg = World$new()
stopifnot(all.equal(ww$greet(), wg$greet()))
wgg <- wg$greet()
ww$set("Other")
stopifnot(all.equal(ww$greet(), "Other"),
all.equal(wg$greet(), "Other"))
World$methods(
twice = function() paste(greet(), greet()))
stopifnot(all.equal(ww$twice(), paste(ww$greet(), ww$greet())))