r - How can I pass higher order functions via ocpu.rpc? -


i'm trying pass function function in opencpu app using ocpu.rpc. know opencpu api can handle because i've tested sapply function in base r (among others) using api test facility.

opencpu accepts functions arguments

however, i've been unable accomplish same thing ocpu.rpc. see http/1.1 400 bad request.

ocpu.rpc("sapply",    {fun: "sqrt", x: [1,4,9,16,25,36]},    function(output) { output } }) 

can provide example how make call (and return json vector) using ocpu.rpc?

i'd ask me create jsfiddle it, have been unable edit fiddles.

jquery or opencpu has been blocked

it turns out can use match.fun turn json argument function expression on r's side. sapply default. had return value wrong. basing code off of lowess example, returns list 2 arguments: x , y.

//set cors call "stocks" package on public server ocpu.seturl("//public.opencpu.org/ocpu/library/base/r")  //some example data var mydata = [1, 4, 9, 16, 25];  //call r function: stats::var(x=data) $("#submitbutton").click(function(){     var req = ocpu.rpc("sapply",{         x : mydata,         fun : "sqrt"     }, function(output){         $("code").text(output.join("\n"));     });       //optional     req.fail(function(){         alert("r returned error: " + req.responsetext);      }); }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -