[Rinside-commits] r142 - in pkg: inst inst/examples/standard src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 26 05:47:13 CET 2010
Author: romain
Date: 2010-03-26 05:47:13 +0100 (Fri, 26 Mar 2010)
New Revision: 142
Modified:
pkg/inst/ChangeLog
pkg/inst/examples/standard/rinside_sample8.cpp
pkg/src/RInside.cpp
pkg/src/RInside.h
Log:
make Proxy use implicit
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-03-25 22:04:29 UTC (rev 141)
+++ pkg/inst/ChangeLog 2010-03-26 04:47:13 UTC (rev 142)
@@ -1,3 +1,11 @@
+2010-03-26 Romain Francois <romain at r-enthusiasts.com>
+
+ * src/RInside.h: the Proxy class is moved inside RInside and parseEval now
+ returns a Proxy so that the proxy class does its job implicitely
+
+ * inst/examples/standard/rinside_sample8.cpp: simplify the example to
+ implicit use of the Proxy class
+
2010-03-25 Dirk Eddelbuettel <edd at debian.org>
* src/RInside.h: New Proxy class with operator T() to borrow
Modified: pkg/inst/examples/standard/rinside_sample8.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample8.cpp 2010-03-25 22:04:29 UTC (rev 141)
+++ pkg/inst/examples/standard/rinside_sample8.cpp 2010-03-26 04:47:13 UTC (rev 142)
@@ -18,13 +18,9 @@
std::cout << "10 + 20 = " << sum << std::endl ;
// we can also return the value directly
- sum = Rcpp::as<int>( R.parseEval("z <- x + y") );
+ sum = R.parseEval("x + y") ;
std::cout << "10 + 20 = " << sum << std::endl ;
- // Or we can use the Proxy() class
- sum = Proxy( R.parseEval("z <- x + y") );
- std::cout << "10 + 20 = " << sum << std::endl ;
-
exit(0);
}
Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp 2010-03-25 22:04:29 UTC (rev 141)
+++ pkg/src/RInside.cpp 2010-03-26 04:47:13 UTC (rev 142)
@@ -292,13 +292,13 @@
}
}
-SEXP RInside::parseEval(const std::string & line) {
+RInside::Proxy RInside::parseEval(const std::string & line) {
SEXP ans;
int rc = parseEval(line, ans);
if (rc != 0) {
throw std::runtime_error(std::string("Error evaluating: ") + line);
}
- return ans;
+ return Proxy( ans );
}
Rcpp::Environment::Binding RInside::operator[]( const std::string& name ){
Modified: pkg/src/RInside.h
===================================================================
--- pkg/src/RInside.h 2010-03-25 22:04:29 UTC (rev 141)
+++ pkg/src/RInside.h 2010-03-26 04:47:13 UTC (rev 142)
@@ -41,7 +41,7 @@
Rcpp::Environment global_env ;
bool verbose_m; // private switch
-
+
void init_tempdir(void);
void init_rand(void);
void autoloads(void);
@@ -51,8 +51,21 @@
public:
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)
- SEXP parseEval(const std::string & line); // parse line, return SEXP (throws on error)
+ class Proxy {
+ public:
+ Proxy(SEXP xx): x(xx) { };
+
+ template <typename T>
+ operator T() {
+ return ::Rcpp::as<T>(x);
+ }
+ private:
+ Rcpp::RObject x;
+ };
+
+ Proxy parseEval(const std::string & line); // parse line, return SEXP (throws on error)
+
template <typename T>
void assign(const T& object, const std::string& nam) {
global_env.assign( nam, object ) ;
@@ -66,18 +79,6 @@
};
-class Proxy {
-public:
- Proxy(SEXP xx): x(xx) { };
-
- template <typename T>
- operator T() {
- return ::Rcpp::as<T>(x);
- }
-private:
- Rcpp::RObject x;
-};
-
// simple logging help
inline void logTxtFunction(const char* file, const int line, const char* expression, const bool verbose) {
if (verbose) {
More information about the Rinside-commits
mailing list