2 import "Serialization"
\r
5 """The effect <R> for a routine means that it needs to be dispatched to an R session using a suitable
\r
6 R execution routine. (syncExec, asyncExec, withConfiguration.)"""
\r
9 "org.rosuda.REngine.Rserve.RConnection"
\r
11 importJava "org.simantics.r.scl.RSessionConfiguration" where
\r
12 """SessionConfiguration is a configuration element for the Session.
\r
14 The fields of the type are: SessionConfiguration <host name> <port number> <user name> <password>"""
\r
15 data SessionConfiguration =
\r
16 @FieldNames [host, port, username, password]
\r
17 SessionConfiguration String Integer String String
\r
19 importJava "org.simantics.r.scl.RSession" where
\r
20 "Session represents an open R session with an Rserve instance."
\r
22 "Execute a given R operation synchronously. sychExec <session> <r operation>."
\r
23 syncExec :: Session -> (<R> a) -> <Proc> a
\r
24 "Execute a given R operation asynchronously. asychExec <session> <r operation>."
\r
25 asyncExec :: Session -> (<R> a) -> <Proc> ()
\r
26 "Get the session id of an open R session."
\r
28 sessionIdOf :: Session -> String
\r
29 "Close the given R session."
\r
31 closeSession :: Session -> <Proc> ()
\r
32 "Refresh the variables of a given R session."
\r
33 @JavaName refreshVariablesSync
\r
34 refreshVariables :: Session -> <Proc> ()
\r
36 importJava "org.simantics.r.scl.RSessionManager" where
\r
37 "Get a session using a given session id."
\r
38 @JavaName getSession
\r
39 sessionById :: String -> <Proc> Maybe Session
\r
40 "Create a new session with a given configuration."
\r
41 createSession :: SessionConfiguration -> <Proc> Session
\r
42 "Execute a given R operation using a temporary session with the given configuration."
\r
43 withConfiguration :: SessionConfiguration-> (<R,e> a) -> <Proc,e> a
\r
44 "Get a session with the given session id or create a new session, if not found."
\r
45 getOrCreateSession :: SessionConfiguration -> String -> <Proc> Session
\r
47 importJava "org.rosuda.REngine.Rserve.RConnection" where
\r
48 "Evaluate an R expression, returning the result as an RExp object."
\r
50 evalRExp:: String -> <R> RExp
\r
51 "Evaluate an R expression and ignore the result."
\r
53 evalR_ :: String -> <R> ()
\r
54 "Evaluate an R expression and return the result as a string."
\r
56 evalRS_ :: String -> <R> String
\r
57 "Assign an RExp value to a variable in R."
\r
59 assignRExp :: String -> RExp -> <R> ()
\r
60 "Create a file on the R server and a return an OutputStream for it."
\r
61 @JavaName createFile
\r
62 createFileR :: String -> <R> OutputStream
\r
63 "Open a file on the R server for reading and return a InputStream for it."
\r
65 openFileR :: String -> <R> InputStream
\r
66 "Remove a file on the R server."
\r
67 @JavaName removeFile
\r
68 removeFileR :: String -> <R> ()
\r
70 "Evaluate an R expression and return the result as an SCL value. May fail, if the value is not compatible with the expected data type."
\r
71 evalR :: RCompatible a => String -> <R> a
\r
72 evalR = fromRExp . evalRExp
\r
74 "Assign an SCL value to a variable in R."
\r
75 assignR :: RCompatible a => String -> a -> <R> ()
\r
76 assignR name = assignRExp name . toRExp
\r
78 "Read the contents of a file on the R server into a string."
\r
79 readFileAsStringR :: String -> <R> String
\r
80 readFileAsStringR name = runProc (readAllString (openFileR name))
\r