There are special code that one can send to R to easily turn the server
(possibly temporarily) into a given configuration. First, if you want to
persistently store parameters for your client in the R server and make sure
you retrieve the same parameters the next time you reconnect, you should
specify your own identifier. This is done by sending <<<id=myID>>>
at the
very beginning of each of your commands. Always remember that, if you do not
specify an identifier, the name of your socket will be used. Since socket
names can be reused, you should always reinitialize the configuration of your
server the first time you connect to it.
Then, sending <<<esc>>>
breaks current multiline code submission and
flushes the multiline buffer.
The sequence <<<q>>>
at the beginning of a command indicates that the
server wants to disconnect once the command is fully treated by R. Similarly,
the sequence <<<Q>>>
tells the server to disconnect the client before
processing the command (no error message is returned to the client!).
It is easy to turn the server to evaluate R code (including multiline code)
and return the result and disconnect by using the <<<e>>>
sequence at the
beginning of a command. Using <<<h>>>
or <<<H>>>
configures that server
to process a (single-line code only) command silently and disconnect before
(uppercase H) or after (lowercase h) processing that command. It is the less
intrusive mode that is very useful for all commands that should be executed
behind the scene between R and a R editor or IDE, like contextual help,
calltips, completion lists, etc.). Note that using these modes in a server
that is, otherwise, configured as a multi-line server does not break current
multi-line buffer.
The other sequences that can be used are: <<<s>>>
for a placeholder to
configure the current server (with configuration parameters after it), and
<<<n>>>
to indicate a newline in your code (submitting two lines of code
as a single one; also works with servers configured as single-line
evaluators).
To debug the R socket server and inspect how commands send by a client are
interpreted by this function, use options(debug.Socket = TRUE)
. This
function uses svMisc::parseText()
and svMisc::captureAll()
in order to
evaluate R code in character string almost exactly the same way as if it was
typed at the command line of a R console.