1- # !/usr/bin/r -t
1+ # !/usr/bin/env r
22#
3- # Copyright (C) 2009 - 2010 Dirk Eddelbuettel and Romain Francois
3+ # Copyright (C) 2009 - 2016 Dirk Eddelbuettel and Romain Francois
44#
55# This file is part of Rcpp.
66#
1818# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
1919
2020suppressMessages(library(Rcpp ))
21+ suppressMessages(library(RcppGSL ))
2122suppressMessages(library(inline ))
2223
2324firstExample <- function () {
@@ -29,22 +30,20 @@ firstExample <- function() {
2930
3031 r = gsl_rng_alloc (gsl_rng_default);
3132
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);
3435 v = gsl_rng_get (r);
35- printf("first value = %.0f\\ n", v);
36+ printf(" first value = %.0f\\ n", v);
3637
3738 gsl_rng_free(r);
3839 return R_NilValue;
3940 '
4041
4142 # # turn into a function that R can call
4243 # # 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" )
4847
4948 cat(" Calling first example\n " )
5049 funx()
@@ -67,9 +66,9 @@ secondExample <- function() {
6766 v = gsl_rng_get (r);
6867
6968 #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);
7372 #endif
7473
7574 gsl_rng_free(r);
@@ -79,19 +78,20 @@ secondExample <- function() {
7978 # # turn into a function that R can call
8079 # # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
8180 # # 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" )
8784 cat(" \n\n Calling second example without -DBeSilent set\n " )
8885 print(funx(0 ))
8986
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 )
9595 cat(" \n\n Calling second example with -DBeSilent set\n " )
9696 print(funx(0 ))
9797
@@ -123,12 +123,10 @@ thirdExample <- function() {
123123 # # turn into a function that R can call
124124 # # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
125125 # # 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" )
132130 cat(" \n\n Calling third example with seed and length\n " )
133131 print(funx(0 , 5 ))
134132
@@ -160,14 +158,12 @@ fourthExample <- function() {
160158 # # turn into a function that R can call
161159 # # compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
162160 # # 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" )
171167 cat(" \n\n Calling fourth example with seed, length and namespaces\n " )
172168 print(funx(0 , 5 ))
173169
0 commit comments