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))