You can assign the environment to a variable, and then, access its content
like if it was a list (e$var
or e$var <- "new value"
). To get a list of
the content, use ls(par_socket_server(client, port))
, or
ls(par_socket_server(client, port), all.names = TRUE)
, but not
names(par_socket_server(client, port))
. As long as you keep a variable
pointing on that environment alive, you have access to last values (i.e.,
changes done elsewhere are taken into account). If you want a frozen snapshot
of the parameters, you should use
myvar <- as.list(par_socket_server(client, port)
.
There is a convenient placeholder for code send by the client to insert
automatically the right socket and server_port in
par_socket_server()
: <<<s>>>
.
Hence, code that the client send to access or change its environment is just
par_socket_server(<<<s>>>, bare = FALSE)
or
par_socket_server(<<<s>>>)$bare
to set or get one parameter. Note that you
can set or change many parameters at once.
Currently, parameters are:
bare = TRUE|FALSE
for "bare" mode (no prompt, no echo, no multiline; by
default, bare = TRUE
),
multiline = TRUE|FALSE
: does the server accept code spread on multiple
lines and send in several steps (by default, yes, but works only if
bare = FALSE
.
echo = TRUE|FALSE
is the command echoed to the regular R console (by
default echo = FALSE
).
last = ""
string to append to each output (for instance to indicate that
processing is done),
prompt = "> "
, the prompt to use (if not in bare mode) and
continue = "+ "
the continuation prompt to use, when multiline mode is
active. You can only cancel a multiline mode by completing the R code you are
sending to the server, but you can break it too by sending <<<esc>>>
before
the next instruction. You can indicate <<<q>>>
or <<<Q>>>
at the very
beginning of an instruction to tell R to disconnect the connection after the
command is processed and result is returned (with <<<q>>>
), or when the
instructions are received but before they are processed (with <<<Q>>>
).
This is useful for "one shot" clients (clients that connect, send code and
want to disconnect immediately after that). The code send by the server to
the client to tell him to disconnect gracefully (and do some housekeeping) is
\\f
send at the beginning of one line. So, clients should detect this and
perform the necessary actions to gracefully disconnect from the server as
soon as possible, and he cannot send further instructions from this moment
on.
For clients that repeatedly connect and disconnect, but want persistent data,
the default client identifier (the socket name) cannot be used, because that
socket name would change from connection to connection. The client must then
provide its own identifier. This is done by sending <<<id=myID>>>
at the
very beginning of a command. This must be done for all commands! myID
must
use only characters or digits. This code could be followed by <<<e>>>
,
<<<h>>>
or <<<H>>>
. These commands are intended for R editors/IDE. The
first code <<<e>>>
sets the server into a mode that is suitable to
evaluate R code (including in a multi-line way). The other code temporarily
configure the server to run the command (in single line mode only) in a
hidden way. They can be used to execute R code without displaying it in the
console (for instance, to start context help, to get a calltip, or a
completion list, etc.). The differences between <<<h>>>
and <<<H>>>
is
that the former waits for command completion and returns results of the
command to the client before disconnecting, while the latter disconnects from
the client before executing the command.
There is a simple client (written in Tcl) available in the /etc subdirectory
of this package installation. Please, read the 'ReadMe.txt' file in the same
directory to learn how to use it. You can use this simple client to
experiment with the communication using these sockets, but it does not
provide advanced command line edition, no command history, and avoid pasting
more than one line of code into it.