Deprecate R scripts in DataFilter/UserMetric

.. since the R interpreter doesn't support multithreading* and this
   is needed for metric computation

   * we could get around this with IPC/signals but decide it was not
     worth the coding effort and maintenance overhead.
This commit is contained in:
Mark Liversedge
2018-04-08 17:09:49 +01:00
parent 352c10e734
commit d9349150f6
7 changed files with 2 additions and 94 deletions

View File

@@ -33,11 +33,6 @@
QMutex pythonMutex;
#endif
#ifdef GC_WANT_R
#include "RTool.h"
QMutex RMutex;
#endif
#include "Zones.h"
#include "PaceZones.h"
#include "HrZones.h"
@@ -2536,9 +2531,6 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, RideItem *m, RideF
// run a script
#ifdef GC_WANT_PYTHON
if (leaf->function == "python") return Result(df->runPythonScript(m->context, *leaf->lvalue.s, m, c, s));
#endif
#ifdef GC_WANT_R
if (leaf->function == "R") return Result(df->runRScript(m->context, *leaf->lvalue.s));
#endif
return Result(0);
}
@@ -3055,52 +3047,3 @@ DataFilterRuntime::runPythonScript(Context *context, QString script, RideItem *m
return result;
}
#endif
#ifdef GC_WANT_R
double
DataFilterRuntime::runRScript(Context *context, QString script)
{
if (rtool == NULL) return(0);
// get the lock
RMutex.lock();
double result=0;
// run it !!
rtool->context = context;
rtool->canvas = NULL;
rtool->chart = NULL;
try {
// run it
rtool->R->parseEval(script);
// ignore errors
rtool->messages.clear();
} catch(std::exception& ex) {
rtool->messages.clear();
} catch(...) {
rtool->messages.clear();
}
// if the program expects more we clear it, otherwise
// weird things can happen!
rtool->R->program.clear();
// clear context
rtool->context = NULL;
result = rtool->R->result;
RMutex.unlock();
return result;
}
#endif

View File

@@ -145,10 +145,6 @@ public:
double runPythonScript(Context *context, QString script, RideItem *m, const QHash<QString,RideMetric*> *metrics, Specification spec);
#endif
#ifdef GC_WANT_R
// embedded R runtime
double runRScript(Context *context, QString script);
#endif
};
class DataFilter : public QObject

View File

@@ -54,7 +54,6 @@ int DataFiltercolumn = 1;
"#"[^\r\n]* ; /* ignore single-line comments */
"%%python"(.|[\n\r\t])*"%%" DataFilterlval.op = PYTHON; return PYTHON;
"%%R"(.|[\n\r\t])*"%%" DataFilterlval.op = RSCRIPT; return RSCRIPT;
"=" DataFilterlval.op = EQ; return EQ;
"<>" DataFilterlval.op = NEQ; return NEQ;
"<" DataFilterlval.op = LT; return LT;

View File

@@ -50,7 +50,7 @@ extern Leaf *DataFilterroot; // root node for parsed statement
%}
// Symbol can be meta or metric name
%token <leaf> SYMBOL RSCRIPT PYTHON
%token <leaf> SYMBOL PYTHON
// Constants can be a string or a number
%token <leaf> DF_STRING DF_INTEGER DF_FLOAT
@@ -77,7 +77,7 @@ extern Leaf *DataFilterroot; // root node for parsed statement
%type <leaf> symbol array literal lexpr cexpr expr parms block statement expression;
%type <leaf> simple_statement if_clause while_clause function_def;
%type <leaf> r_script python_script;
%type <leaf> python_script;
%type <comp> statements
%right '?' ':'
@@ -187,16 +187,6 @@ python_script:
}
;
r_script:
RSCRIPT { $$ = new Leaf(@1.first_column, @1.last_column);
$$->type = Leaf::Script;
$$->function = "R";
QString full(DataFiltertext);
$$->lvalue.s = new QString(full.mid(3,full.length()-5));
}
;
/*
* if then else clause AST is same as a ternary
* dangling else handled by bison default shift
@@ -477,7 +467,6 @@ expr:
| array { $$ = $1; }
| literal { $$ = $1; }
| symbol { $$ = $1; }
| r_script { $$ = $1; }
| python_script { $$ = $1; }
;

View File

@@ -75,9 +75,6 @@ class REmbed {
bool interactive;
bool loaded;
// can be set by a script
double result;
};
#endif

View File

@@ -114,7 +114,6 @@ RTool::RTool()
// setup when embedding v3.4 or higher
R_CMethodDef34 cMethods34[] = {
{ "GC.display", (DL_FUNC) &RGraphicsDevice::GCdisplay, 0,0 },
{ "GC.result", (DL_FUNC) &RTool::result, 0,0 },
{ "GC.page", (DL_FUNC) &RTool::pageSize, 0,0 },
{ "GC.size", (DL_FUNC) &RTool::windowSize, 0,0 },
{ "GC.athlete", (DL_FUNC) &RTool::athlete, 0,0 },
@@ -137,7 +136,6 @@ RTool::RTool()
// setup when embedding prior to 3.4
R_CMethodDef33 cMethods33[] = {
{ "GC.display", (DL_FUNC) &RGraphicsDevice::GCdisplay, 0,0,0 },
{ "GC.result", (DL_FUNC) &RTool::result, 0,0,0 },
{ "GC.page", (DL_FUNC) &RTool::pageSize, 0,0,0 },
{ "GC.size", (DL_FUNC) &RTool::windowSize, 0,0,0 },
{ "GC.athlete", (DL_FUNC) &RTool::athlete, 0,0,0 },
@@ -159,7 +157,6 @@ RTool::RTool()
R_CallMethodDef callMethods[] = {
{ "GC.display", (DL_FUNC) &RGraphicsDevice::GCdisplay, 0 },
{ "GC.result", (DL_FUNC) &RTool::result, 1 },
{ "GC.page", (DL_FUNC) &RTool::pageSize, 2 },
{ "GC.size", (DL_FUNC) &RTool::windowSize, 0 },
@@ -251,7 +248,6 @@ RTool::RTool()
// graphics device
"GC.display <- function() { .Call(\"GC.display\") }\n"
"GC.result <- function(result=0) { .Call(\"GC.result\", result) }\n"
"GC.page <- function(width=0, height=0) { .Call(\"GC.page\", width, height) }\n"
"GC.size <- function() { .Call(\"GC.size\") }\n"
@@ -852,15 +848,6 @@ RTool::zones(SEXP pDate, SEXP pSport)
}
SEXP
RTool::result(SEXP value)
{
value = Rf_coerceVector(value, REALSXP);
rtool->R->result = REAL(value)[0];
return Rf_allocVector(INTSXP, 0);
}
SEXP
RTool::pageSize(SEXP width, SEXP height)
{

View File

@@ -47,9 +47,6 @@ class RTool {
static SEXP windowSize();
static SEXP pageSize(SEXP width, SEXP height);
// passing back results
static SEXP result(SEXP value);
// athlete
static SEXP athlete();
static SEXP zones(SEXP date, SEXP sport);