1
- # !/usr/bin/r -t
1
+ # !/usr/bin/env r
2
2
#
3
- # Copyright (C) 2009 - 2010 Dirk Eddelbuettel and Romain Francois
3
+ # Copyright (C) 2009 - 2016 Dirk Eddelbuettel and Romain Francois
4
4
#
5
5
# This file is part of Rcpp.
6
6
#
18
18
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19
19
20
20
suppressMessages(library(Rcpp ))
21
+ suppressMessages(library(RcppGSL ))
21
22
suppressMessages(library(inline ))
22
23
23
24
firstExample <- function () {
@@ -29,22 +30,20 @@ firstExample <- function() {
29
30
30
31
r = gsl_rng_alloc (gsl_rng_default);
31
32
32
- printf("generator type: %s\\ n", gsl_rng_name (r));
33
- printf("seed = %lu\\ n", gsl_rng_default_seed);
33
+ printf(" generator type: %s\\ n", gsl_rng_name (r));
34
+ printf(" seed = %lu\\ n", gsl_rng_default_seed);
34
35
v = gsl_rng_get (r);
35
- printf("first value = %.0f\\ n", v);
36
+ printf(" first value = %.0f\\ n", v);
36
37
37
38
gsl_rng_free(r);
38
39
return R_NilValue;
39
40
'
40
41
41
42
# # turn into a function that R can call
42
43
# # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
43
- funx <- cfunction(signature(), gslrng ,
44
- includes = " #include <gsl/gsl_rng.h>" ,
45
- Rcpp = FALSE ,
46
- cppargs = " -I/usr/include" ,
47
- libargs = " -lgsl -lgslcblas" )
44
+ funx <- cxxfunction(signature(), gslrng ,
45
+ includes = " #include <gsl/gsl_rng.h>" ,
46
+ plugin = " RcppGSL" )
48
47
49
48
cat(" Calling first example\n " )
50
49
funx()
@@ -67,9 +66,9 @@ secondExample <- function() {
67
66
v = gsl_rng_get (r);
68
67
69
68
#ifndef BeSilent
70
- printf("generator type: %s\\ n", gsl_rng_name (r));
71
- printf("seed = %d\\ n", seed);
72
- printf("first value = %.0f\\ n", v);
69
+ printf(" generator type: %s\\ n", gsl_rng_name (r));
70
+ printf(" seed = %d\\ n", seed);
71
+ printf(" first value = %.0f\\ n", v);
73
72
#endif
74
73
75
74
gsl_rng_free(r);
@@ -79,19 +78,20 @@ secondExample <- function() {
79
78
# # turn into a function that R can call
80
79
# # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
81
80
# # use additional define for compile to suppress output
82
- funx <- cfunction(signature(par = " numeric" ), gslrng ,
83
- includes = " #include <gsl/gsl_rng.h>" ,
84
- Rcpp = TRUE ,
85
- cppargs = " -I/usr/include" ,
86
- libargs = " -lgsl -lgslcblas" )
81
+ funx <- cxxfunction(signature(par = " numeric" ), gslrng ,
82
+ includes = " #include <gsl/gsl_rng.h>" ,
83
+ plugin = " RcppGSL" )
87
84
cat(" \n\n Calling second example without -DBeSilent set\n " )
88
85
print(funx(0 ))
89
86
90
- funx <- cfunction(signature(par = " numeric" ), gslrng ,
91
- includes = " #include <gsl/gsl_rng.h>" ,
92
- Rcpp = TRUE ,
93
- cppargs = " -I/usr/include -DBeSilent" ,
94
- libargs = " -lgsl -lgslcblas" )
87
+
88
+ # # now override settings to add -D flag
89
+ settings <- getPlugin(" RcppGSL" )
90
+ settings $ env $ PKG_CPPFLAGS <- paste(settings $ PKG_CPPFLAGS , " -DBeSilent" )
91
+
92
+ funx <- cxxfunction(signature(par = " numeric" ), gslrng ,
93
+ includes = " #include <gsl/gsl_rng.h>" ,
94
+ settings = settings )
95
95
cat(" \n\n Calling second example with -DBeSilent set\n " )
96
96
print(funx(0 ))
97
97
@@ -123,12 +123,10 @@ thirdExample <- function() {
123
123
# # turn into a function that R can call
124
124
# # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
125
125
# # use additional define for compile to suppress output
126
- funx <- cfunction(signature(s = " numeric" , n = " numeric" ),
127
- gslrng ,
128
- includes = " #include <gsl/gsl_rng.h>" ,
129
- Rcpp = TRUE ,
130
- cppargs = " -I/usr/include" ,
131
- libargs = " -lgsl -lgslcblas" )
126
+ funx <- cxxfunction(signature(s = " numeric" , n = " numeric" ),
127
+ gslrng ,
128
+ includes = " #include <gsl/gsl_rng.h>" ,
129
+ plugin = " RcppGSL" )
132
130
cat(" \n\n Calling third example with seed and length\n " )
133
131
print(funx(0 , 5 ))
134
132
@@ -160,14 +158,12 @@ fourthExample <- function() {
160
158
# # turn into a function that R can call
161
159
# # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
162
160
# # use additional define for compile to suppress output
163
- funx <- cfunction(signature(s = " numeric" , n = " numeric" ),
164
- gslrng ,
165
- includes = c(" #include <gsl/gsl_rng.h>" ,
166
- " using namespace Rcpp;" ,
167
- " using namespace std;" ),
168
- Rcpp = TRUE ,
169
- cppargs = " -I/usr/include" ,
170
- libargs = " -lgsl -lgslcblas" )
161
+ funx <- cxxfunction(signature(s = " numeric" , n = " numeric" ),
162
+ gslrng ,
163
+ includes = c(" #include <gsl/gsl_rng.h>" ,
164
+ " using namespace Rcpp;" ,
165
+ " using namespace std;" ),
166
+ plugin = " RcppGSL" )
171
167
cat(" \n\n Calling fourth example with seed, length and namespaces\n " )
172
168
print(funx(0 , 5 ))
173
169
0 commit comments