瀏覽代碼

HPCC-17280 Embedded R code uses persistent, shared environment

Made a change to work around the fact that the two-parameter form of _new_env
does not appear to be present in older versions of Rcpp.

We could take the view that updating the version of Rcpp on the build machines
is preferable in whcih case this commit should be removed.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 年之前
父節點
當前提交
f7570c993f
共有 2 個文件被更改,包括 12 次插入2 次删除
  1. 10 2
      plugins/Rembed/Rembed.cpp
  2. 2 0
      testing/regress/ecl/modelingWithR.ecl

+ 10 - 2
plugins/Rembed/Rembed.cpp

@@ -97,6 +97,14 @@ extern "C" DECL_EXPORT bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
 
 namespace Rembed
 {
+// Copied from Rcpp 3.3's environment.h, in case an older version of Rcpp is in use
+inline Rcpp::Environment _new_env(SEXP parent, int size = 29) {
+    Rcpp::Shield<SEXP> sizeSEXP(Rf_ScalarInteger(size));
+    Rcpp::Shield<SEXP> parentSEXP(parent);
+    return R_NewHashedEnv(parentSEXP, sizeSEXP);
+}
+
+
 
 __declspec(noreturn) static void failx(const char *msg, ...) __attribute__((format(printf, 1, 2), noreturn));
 
@@ -179,7 +187,7 @@ public:
         Linked<REnvironment> ret = preservedScopes.getValue(key);
         if (!ret)
         {
-            ret.setown(new REnvironment(Rcpp::new_env(Rcpp::Environment::global_env())));
+            ret.setown(new REnvironment(_new_env(Rcpp::Environment::global_env())));
             preservedScopes.setValue(key, ret);  // NOTE - links arg
             isNew = true;
         }
@@ -690,7 +698,7 @@ public:
                 engine->onTermination(RGlobalState::unregister, scopeKey.str(), wuidScope);
         }
         else
-            env.setown(new REnvironment(Rcpp::new_env(Rcpp::Environment::global_env())));
+            env.setown(new REnvironment(_new_env(Rcpp::Environment::global_env())));
     }
     ~REmbedFunctionContext()
     {

+ 2 - 0
testing/regress/ecl/modelingWithR.ecl

@@ -18,6 +18,8 @@
 // The following script uses embeded R code to train some models on data passed to R
 // from HPCC. The results are then returned to HPCC and output.
 
+//nothor
+
 IMPORT R;
 
 ////// Get some example data from R (in practice this may be a dataset on the ECL side)