问题
How do I access a specific object in an opencpu "session" in a subsequent function call?
Given a request, say to
/ocpu/library/base/R/eval
with parameter
expr = "x <- 10; y <- 20"
Which gives
/ocpu/tmp/x08dfddafe3/R/.val
/ocpu/tmp/x08dfddafe3/R/x
/ocpu/tmp/x08dfddafe3/R/y
/ocpu/tmp/x08dfddafe3/stdout
/ocpu/tmp/x08dfddafe3/source
/ocpu/tmp/x08dfddafe3/console
/ocpu/tmp/x08dfddafe3/info
Now .val
has the value 20.
Suppose I wanted to pass x
to
ocpu/library/stats/R/rnorm
Is there a quick way to that, something like
n = x08dfddafe3/R/x
in "pseudo"...
回答1:
Great question. Starting version 1.4.4
there are two ways of doing this:
- You can use
x08dfddafe3::x
to refer to objectx
in the namespace of sessionx08dfddafe3
. - You can pass the full URL http://your.server.com/ocpu/tmp/x08dfddafe3/R/x/rds. If network permits, this will automaticaly grab the object and unserialize it.
来源:https://stackoverflow.com/questions/24722550/accessing-objects-in-opencpu-sessions