registerRshareHook: Register an Rshare Hook

Description Usage Arguments Value Details Examples

View source: R/hooks.R

Description

Hooks can be used to trigger certain actions when an object of a particular type is sent to the Rshare server. These hooks are simple, and can be used for a wide variety of purposes allowing for flexible interprocess communication and control between R sessions. Hooks may be created from both Rshare server sessions and client sessions using this function.

Usage

1
2
  registerRshareHook(objType, hookFunction, port = 7777,
    doResponse = FALSE, overwriteExisting = FALSE)

Arguments

objType

name of the type/class of the objects which will trigger the hook.

hookFunction

the hook function. See details.

port

the Rshare port number.

doResponse

logical; whether server hook returns a response to client when executed. Default is FALSE.

overwriteExisting

logical; should existing objType hook be overwritten? Default is FALSE.

Value

invisibly returns a logical indicating whether hook registration was a success or not.

Details

The hook function may have just two formal arguments: obj and optionally, port. The object sent to the Rshare server will be passed to the obj argument and thus should contain all data (other than the Rshare port number) required for the hook function. The optional port argument will be a single integer specifying the Rshare port number. If port is not an argument to hookFunction it will not be passed to the hook function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
# Start Rshare server on port 7777 (the default) and register hook
startRshare()
registerRshareHook("printMsg", function(obj, port) cat("Rshare message on port",port,"-",obj$msg,"\n"))

# In a different R session, start Rshare client, and create an object of type 'printMsg'
startRshare()
obj <- list(msg="Hello World!")
class(obj) <- "printMsg"

# Send that object to the Rshare server, and watch the server session console
sendRshare(obj)

## End(Not run)

Rshare documentation built on May 2, 2019, 5:23 p.m.