X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.r.scl%2Fscl%2FR%2FR.scl;h=dc542d5c2a1521544b9666d4cdf4e3c2575ab442;hb=c43c222434e58130299ad9bfc797718d49f52989;hp=ef82084007b8a0a9fbecbf96063cffd5769f3752;hpb=2e278cf242c87a7851c68d6c5f03f169e28d3a7e;p=simantics%2Fr.git diff --git a/org.simantics.r.scl/scl/R/R.scl b/org.simantics.r.scl/scl/R/R.scl index ef82084..dc542d5 100644 --- a/org.simantics.r.scl/scl/R/R.scl +++ b/org.simantics.r.scl/scl/R/R.scl @@ -2,58 +2,76 @@ import "Stream" import "Serialization" include "R/RExp" +"""The effect for a routine means that it needs to be dispatched to an R session using a suitable +R execution routine. (syncExec, asyncExec, withConfiguration.)""" effect R "r" "org.rosuda.REngine.Rserve.RConnection" importJava "org.simantics.r.scl.RSessionConfiguration" where + """SessionConfiguration is a configuration element for the Session. + + The fields of the type are: SessionConfiguration """ data SessionConfiguration = @FieldNames [host, port, username, password] SessionConfiguration String Integer String String importJava "org.simantics.r.scl.RSession" where + "Session represents an open R session with an Rserve instance." data Session + "Execute a given R operation synchronously. sychExec ." syncExec :: Session -> ( a) -> a + "Execute a given R operation asynchronously. asychExec ." asyncExec :: Session -> ( a) -> () + "Get the session id of an open R session." @JavaName getId sessionIdOf :: Session -> String + "Close the given R session." @JavaName close closeSession :: Session -> () + "Refresh the variables of a given R session." @JavaName refreshVariablesSync refreshVariables :: Session -> () importJava "org.simantics.r.scl.RSessionManager" where + "Get a session using a given session id." @JavaName getSession sessionById :: String -> Maybe Session + "Create a new session with a given configuration." createSession :: SessionConfiguration -> Session + "Execute a given R operation using a temporary session with the given configuration." withConfiguration :: SessionConfiguration-> ( a) -> a + "Get a session with the given session id or create a new session, if not found." getOrCreateSession :: SessionConfiguration -> String -> Session importJava "org.rosuda.REngine.Rserve.RConnection" where + "Evaluate an R expression, returning the result as an RExp object." @JavaName eval evalRExp:: String -> RExp + "Evaluate an R expression and ignore the result." @JavaName voidEval evalR_ :: String -> () + "Evaluate an R expression and return the result as a string." @JavaName voidEvalS evalRS_ :: String -> String + "Assign an RExp value to a variable in R." @JavaName assign assignRExp :: String -> RExp -> () + "Create a file on the R server and a return an OutputStream for it." @JavaName createFile createFileR :: String -> OutputStream + "Open a file on the R server for reading and return a InputStream for it." @JavaName openFile openFileR :: String -> InputStream +"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." evalR :: RCompatible a => String -> a evalR = fromRExp . evalRExp +"Assign an SCL value to a variable in R." assignR :: RCompatible a => String -> a -> () assignR name = assignRExp name . toRExp +"Read the contents of a file on the R server into a string." readFileAsStringR :: String -> String readFileAsStringR name = runProc (readAllString (openFileR name)) - -test () = do - conf = SessionConfiguration "130.188.198.138" 6311 "simupedia" "simupedia" - session = createSession conf - print $ syncExec session (evalR "1+1") - closeSession session \ No newline at end of file