]> gerrit.simantics Code Review - simantics/r.git/blob - org.simantics.r.scl/scl/R/R.scl
(refs #6833) Test RExp inheritance in SCL
[simantics/r.git] / org.simantics.r.scl / scl / R / R.scl
1 import "Stream"\r
2 import "Serialization"\r
3 include "R/RExp"\r
4 \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
7 effect R \r
8     "r" \r
9     "org.rosuda.REngine.Rserve.RConnection"\r
10 \r
11 importJava "org.simantics.r.scl.RSessionConfiguration" where\r
12     """SessionConfiguration is a configuration element for the Session.\r
13     \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
18 \r
19 importJava "org.simantics.r.scl.RSession" where\r
20     "Session represents an open R session with an Rserve instance."\r
21     data Session\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
27     @JavaName getId\r
28     sessionIdOf :: Session -> String\r
29     "Close the given R session." \r
30     @JavaName close\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
35 \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
46     \r
47 importJava "org.rosuda.REngine.Rserve.RConnection" where\r
48     "Evaluate an R expression, returning the result as an RExp object." \r
49     @JavaName eval\r
50     evalRExp:: String -> <R> RExp\r
51     "Evaluate an R expression and ignore the result." \r
52     @JavaName voidEval\r
53     evalR_ :: String -> <R> ()\r
54     "Evaluate an R expression and return the result as a string." \r
55     @JavaName voidEvalS\r
56     evalRS_ :: String -> <R> String\r
57     "Assign an RExp value to a variable in R." \r
58     @JavaName assign\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
64     @JavaName openFile\r
65     openFileR :: String -> <R> InputStream\r
66 \r
67 "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
68 evalR :: RCompatible a => String -> <R> a\r
69 evalR = fromRExp . evalRExp\r
70 \r
71 "Assign an SCL value to a variable in R." \r
72 assignR :: RCompatible a => String -> a -> <R> ()\r
73 assignR name = assignRExp name . toRExp\r
74 \r
75 "Read the contents of a file on the R server into a string."\r
76 readFileAsStringR :: String -> <R> String\r
77 readFileAsStringR name = runProc (readAllString (openFileR name))\r