behrica / R-clj

Common protocol to call R from Clojure
Eclipse Public License 1.0
1 stars 1 forks source link

OpenCPU versus rincanter and state #2

Open behrica opened 10 years ago

behrica commented 10 years ago

There is a fundamental difference between OpenCPU and rincater/jvmr.

OpenCPU is stateless. Each call to the OpenCPU executes in an "empty" R environment.

This makes it very hard to define common behavior via the protocol. Lets take some examples:

lets assume we want to execute a function in R:

seq(1,10)

I could see how the call to the R protocol as I defined here usecase.md

(call-R-function a-context "base" "seq" {:from 1 :to 10}) 

could be implemented via clj-opencpu and rincanter in the same way.

Now lets assume, that we want to call this:

seq(a,10)

(so "a" is taken from the environment). Even though it is syntactically possible to do such a call with OpenCPU

(call-R-function a-context "base" "seq" {:from "a" :to 10})   ;quotes around a get removed
=> "object 'a' not found\n\nIn call:\nseq(from = a, to = 10)\n" 

it can never work, as all calls to OpenCPU work in isolation. (so in an empty environment). It is not possible to "set variables" before doing a call. (what is possible is to "reuse" results from previous calls via the session API). But this would work like this:

(call-R-function a-context "base" "identity" {:x "a<-1"}) 
["/ocpu/tmp/x043492d978/R/a" 
"/ocpu/tmp/x043492d978/R/.val" 
...]
 (call-R-function "http://localhost:6124" "base" "seq" {:from "x043492d978" :to 10} :json)
=> (1 2 3 4 5 6 7 8 9 10)

So the session id of the result of the first call can be passed as a parameter to the second.

The rincanter implementation might get this example working (if the variable was set somehow before)

So a opencpu backed implementation of the R protocol can never call successfully (in no circumstances), an R function call like "seq(a,10)" while a rincanter backed can make it work "under condition that "a" was defined before").

This is a big problem for a common interface, right ?

Any comment ?