[Rinside-commits] r176 - in pkg: inst inst/examples/standard inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jul 9 22:59:14 CEST 2010
Author: edd
Date: 2010-07-09 22:59:14 +0200 (Fri, 09 Jul 2010)
New Revision: 176
Modified:
pkg/inst/ChangeLog
pkg/inst/examples/standard/rinside_module_sample0.cpp
pkg/inst/include/RInside.h
pkg/src/RInside.cpp
Log:
new option to load Rcpp package if needed
enabled in modules sample
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-07-09 20:32:03 UTC (rev 175)
+++ pkg/inst/ChangeLog 2010-07-09 20:59:14 UTC (rev 176)
@@ -1,6 +1,8 @@
2010-07-09 Dirk Eddelbuettel <edd at debian.org>
- * src/RInside.cpp: Load Rcpp more quietly
+ * inst/include/RInside.h: New argument to constructor to select
+ loading of Rcpp
+ * src/RInside.cpp: Idem, also load Rcpp more quietly
2010-07-05 Dirk Eddelbuettel <edd at debian.org>
Modified: pkg/inst/examples/standard/rinside_module_sample0.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_module_sample0.cpp 2010-07-09 20:32:03 UTC (rev 175)
+++ pkg/inst/examples/standard/rinside_module_sample0.cpp 2010-07-09 20:59:14 UTC (rev 176)
@@ -1,4 +1,4 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4; -*-
//
// Simple example showing how expose a C++ function
//
@@ -20,8 +20,8 @@
int main(int argc, char *argv[]) {
- // create an embedded R instance
- RInside R(argc, argv);
+ // create an embedded R instance -- and load Rcpp so that modules work
+ RInside R(argc, argv, true);
// load the bling module
R["bling"] = LOAD_RCPP_MODULE(bling) ;
Modified: pkg/inst/include/RInside.h
===================================================================
--- pkg/inst/include/RInside.h 2010-07-09 20:32:03 UTC (rev 175)
+++ pkg/inst/include/RInside.h 2010-07-09 20:59:14 UTC (rev 176)
@@ -1,4 +1,4 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
//
// RInside.h: R/C++ interface class library -- Easier R embedding into C++
//
@@ -32,12 +32,12 @@
Rcpp::Environment global_env ;
bool verbose_m; // private switch
-
+
void init_tempdir(void);
void init_rand(void);
void autoloads(void);
- void initialize(const int argc, const char* const argv[] ) ;
+ void initialize(const int argc, const char* const argv[], const bool loadRcpp ) ;
static RInside* instance_ ;
@@ -56,13 +56,13 @@
int parseEval(const std::string & line, SEXP &ans); // parse line, return in ans; error code rc
void parseEvalQ(const std::string & line); // parse line, no return (throws on error)
- class Proxy {
+ class Proxy {
public:
Proxy(SEXP xx): x(xx) { };
template <typename T>
operator T() {
- return ::Rcpp::as<T>(x);
+ return ::Rcpp::as<T>(x);
}
private:
Rcpp::RObject x;
@@ -72,11 +72,11 @@
template <typename T>
void assign(const T& object, const std::string& nam) {
- global_env.assign( nam, object ) ;
+ global_env.assign( nam, object ) ;
}
RInside() ;
- RInside(const int argc, const char* const argv[]);
+ RInside(const int argc, const char* const argv[], const bool loadRcpp=false);
~RInside();
Rcpp::Environment::Binding operator[]( const std::string& name ) ;
Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp 2010-07-09 20:32:03 UTC (rev 175)
+++ pkg/src/RInside.cpp 2010-07-09 20:59:14 UTC (rev 176)
@@ -55,19 +55,19 @@
: callbacks(0)
#endif
{
- initialize( 0, 0 );
+ initialize( 0, 0, false );
}
-RInside::RInside(const int argc, const char* const argv[])
+RInside::RInside(const int argc, const char* const argv[], const bool loadRcpp)
#ifdef RINSIDE_CALLBACKS
: callbacks(0)
#endif
{
-initialize( argc, argv );
+ initialize( argc, argv, loadRcpp );
}
// TODO: use a vector<string> would make all this a bit more readable
-void RInside::initialize(const int argc, const char* const argv[]){
+void RInside::initialize(const int argc, const char* const argv[], const bool loadRcpp) {
logTxt("RInside::ctor BEGIN", verbose);
if( instance_ ){
@@ -120,12 +120,13 @@
autoloads(); // Force all default package to be dynamically required */
- // load Rcpp
- //Rf_eval( Rf_mkString("suppressMessages(library(Rcpp))"), R_GlobalEnv );
- Rf_eval(Rf_lang2(Rf_install( "suppressMessages" ),
- Rf_lang2(Rf_install( "require" ), Rf_mkString("Rcpp"))),
- R_GlobalEnv);
-
+ // if asked for, load Rcpp
+ if (loadRcpp) {
+ Rf_eval(Rf_lang2(Rf_install( "suppressMessages" ),
+ Rf_lang2(Rf_install( "require" ), Rf_mkString("Rcpp"))),
+ R_GlobalEnv);
+ }
+
if ((argc - optind) > 1){ // for argv vector in Global Env */
Rcpp::CharacterVector s_argv( argv+(1+optind), argv+argc );
assign(s_argv, "argv");
More information about the Rinside-commits
mailing list