From 2e94d450597eb7147889cc8d349cbd9c14b1ca19 Mon Sep 17 00:00:00 2001 From: DavidSichau Date: Fri, 16 Oct 2015 14:16:01 +0200 Subject: [PATCH 1/2] Parameter to allow to enforce JSON Some R objects cannot be converted to json. However opencpu can be force to return a json object by passing the force parameter. --- opencpu-0.5.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/opencpu-0.5.js b/opencpu-0.5.js index 67d3815..d2f1576 100644 --- a/opencpu-0.5.js +++ b/opencpu-0.5.js @@ -28,15 +28,18 @@ if(!window.jQuery) { //new Session() - function Session(loc, key, txt){ + function Session(loc, key, txt, force){ this.loc = loc; this.key = key; this.txt = txt; + this.force = force; this.output = txt.split(/\r\n|\r|\n/g); this.getKey = function(){ return key; }; + + this. this.getLoc = function(){ return loc; @@ -67,6 +70,9 @@ if(!window.jQuery) { } var url = this.getLoc() + "R/" + name + "/json"; + if(this.force) { + url = url + "?force=true"; + } return $.get(url, data, success); }; @@ -154,7 +160,7 @@ if(!window.jQuery) { if(r_cors && loc.match("^/[^/]")){ loc = r_path.protocol + "//" + r_path.host + loc; } - handler(new Session(loc, key, txt)); + handler(new Session(loc, key, txt, ocpu.settings.force)); }).fail(function(){ console.log("OpenCPU error HTTP " + jqxhr.status + "\n" + jqxhr.responseText); }); @@ -439,6 +445,9 @@ if(!window.jQuery) { ocpu.call = r_fun_call; ocpu.rpc = rpc; ocpu.seturl = seturl; + ocpu.settings = { + force: false + } //exported constructors ocpu.Snippet = Snippet; From 827defe24b18cfac11213ba8df3fb1aeaa3a217e Mon Sep 17 00:00:00 2001 From: DavidSichau Date: Fri, 16 Oct 2015 14:16:01 +0200 Subject: [PATCH 2/2] Parameter to allow to enforce JSON Some R objects cannot be converted to json. However opencpu can be force to return a json object by passing the force parameter. Therefore the ocpu has a new settings object. To enforce json one can simply define `ocpu.settings.force = true;` before making a call to getObject(). --- opencpu-0.5.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/opencpu-0.5.js b/opencpu-0.5.js index 67d3815..12861e4 100644 --- a/opencpu-0.5.js +++ b/opencpu-0.5.js @@ -28,16 +28,17 @@ if(!window.jQuery) { //new Session() - function Session(loc, key, txt){ + function Session(loc, key, txt, force){ this.loc = loc; this.key = key; this.txt = txt; + this.force = force; this.output = txt.split(/\r\n|\r|\n/g); this.getKey = function(){ return key; }; - + this.getLoc = function(){ return loc; }; @@ -67,6 +68,9 @@ if(!window.jQuery) { } var url = this.getLoc() + "R/" + name + "/json"; + if(this.force) { + url = url + "?force=true"; + } return $.get(url, data, success); }; @@ -154,7 +158,7 @@ if(!window.jQuery) { if(r_cors && loc.match("^/[^/]")){ loc = r_path.protocol + "//" + r_path.host + loc; } - handler(new Session(loc, key, txt)); + handler(new Session(loc, key, txt, ocpu.settings.force)); }).fail(function(){ console.log("OpenCPU error HTTP " + jqxhr.status + "\n" + jqxhr.responseText); }); @@ -439,6 +443,9 @@ if(!window.jQuery) { ocpu.call = r_fun_call; ocpu.rpc = rpc; ocpu.seturl = seturl; + ocpu.settings = { + force: false + } //exported constructors ocpu.Snippet = Snippet;