Interfaces/R/Rserve/Methods

From J Wiki
< Interfaces‎ | R‎ | Rserve
Jump to navigation Jump to search
Rserve | Installation | Methods | Formats | Examples | Quirks | Extensions

The rserve script populates locale rserve with the core methods for communicating with R. Load with:

load 'stats/r/rserve'

Methods

Each method begins with prefix "rd" (R driver).

rdopen open connection to R (if not already open)
rdclose close connection
rdcmd send command, wth no response
rdget send command, return response in map format
rdgetexp send command, return response in SEXP format
rdset set name in R to value. Form is: name(s) Rset value(s)

A corresponding set of interactive methods is defined in z, with names prefixed 'R', for example:

  Rcmd_z_=: rdcmd_rserve_

See Formats for an explanation of the different result formats.

Event Handling

Rserve methods return only their results, and not a returncode.

If an error occurs, such as a bad format in an Rserve result, then:

  • an error message is written to noun throwtext_rserve_
  • if debug is on (13!:0[1) and noun FORCETHROW_rserve_ is 0, then the error message is displayed in a information box and a stop is put on all verbs in the stack. This suspends the current verb and allows the state to be examined.

This appropriate for development purposes.

  • otherwise, the error message is written to the J session, and a throw. is executed. This is appropriate for production use, and means that a sequence of calls to R should be wrapped in a try./catcht. block.