Objects from this class handle the "higher-level" interaction between the frontend and the R session. There can be more such interfaces to a session. For example, for the main REPL and for a REPL created by a call to browser().
Public fields
session
An RKernelSession object or `NULL`
prompt
The R console prompt or NULL
browse_prompt
The prompt created by a call to `browser()`
io_timeout
An integer number a timeout in microseconds
stdout
Accumulated output via the stdout channel.
stderr
Accumulated output via the stderr channel.
stdout_callback
A function to be called with stdout text or NULL
stderr_callback
A function to be called with stderr text or NULL
browser_callback
A function to be called when a browser prompt is encountered or NULL
prompt_callback
A function to be called when a command prompt is encountered or NULL
input_callback
A function to be called when input is required or NULL
echo
A logical value, if TRUE code sent to the R process will be echoed
found_prompt
A logical value, whether a prompt has been found in the output of the R process
found_browse_prompt
The latest instance of the browser prompt pattern found in the R process output
errored
A logical value, whether an error occurred in the R session
Methods
Method aggreg_stdout()
A potential "stdout_callback" function that aggregates output sent from the R process via "stdout" channel to the eponymous "stdout" field
Method aggreg_stderr()
A potential "stderr_callback" function that aggregates output sent from the R process via "stderr" channel to the eponymous "stderr" field
Method collect()
Collect the accumulated output from fields "stdout" and "stderr" into a list with two elements named "stdout" and "stderr".
Method new()
Initialize an object
Usage
RSessionAdapter$new(
session,
stdout_callback = self$aggreg_stdout,
stderr_callback = self$aggreg_stderr,
browser_callback = NULL,
prompt_callback = NULL,
input_callback = NULL,
prompt = "> ",
echo = FALSE
)
Arguments
session
An object from class "RKernelSession"
stdout_callback
A callback function for "stdout" output
stderr_callback
A callback function for "stderr" output
browser_callback
A callback function for browser prompts (optional)
prompt_callback
A callback function for command prompts encountered
input_callback
A callback function for input requests (optional)
prompt
A character string, the expected command prompt
echo
A logical value, whether to echo input
Method run_code()
Run code and pass output to callback functions
Usage
RSessionAdapter$run_code(
code,
io_timeout = 1,
stdout_callback = self$stdout_callback,
stderr_callback = self$stderr_callback,
browser_callback = self$browser_callback,
prompt_callback = self$prompt_callback,
input_callback = self$input_callback,
until_prompt = TRUE,
echo = self$echo,
debug = FALSE
)
Arguments
code
A character string or character vector with code lines
io_timeout
An integer value, the timeout of waiting for output
stdout_callback
A callback function for "stdout" output
stderr_callback
A callback function for "stderr" output
browser_callback
A callback function for browser prompts (optional)
prompt_callback
A callback function for command prompts encountered
input_callback
A callback function for input requests (optional)
until_prompt
A logical value, whether process and wait output until a command prompt is encountered.
echo
A logical value, whether to echo input
Method interrupt()
Send an interrupt signal (SIGINT) to the R process. This should stop what the R process is doing without killing it.
Method process_output()
Process output created by commands sent to the R process
Usage
RSessionAdapter$process_output(
io_timeout = 1,
stdout_callback = self$stdout_callback,
stderr_callback = self$stderr_callback,
browser_callback = self$browser_callback,
input_callback = self$input_callback,
prompt_callback = self$prompt_callback,
drop_echo = FALSE,
debug = FALSE
)
Arguments
io_timeout
An integer value, the timeout of waiting for output
stdout_callback
A callback function for "stdout" output
stderr_callback
A callback function for "stderr" output
browser_callback
A callback function for browser prompts (optional)
input_callback
A callback function for input requests (optional)
prompt_callback
A callback function for command prompts encountered
drop_echo
A logical value, whether input echo be dropped
until_prompt
A logical value, whether process and wait output until a command prompt is encountered.
Method getOption()
Get an option value from the R session
Method eval()
Evaluate an expression in the R session and return the result.
Method get()
Get the value of a variable (named object) from the R session and return it.
Method assign()
Assign a value to a variable in the R session
Method handle_readline()
Handle special an input request obtained from the R session via output indicated with a special output string
Arguments
txt
Output string containing a special readline prompt
input_callback
A function to request input from the frontend
stdout_callback
A function to process output obtained from the R session via "stdout" channel
stderr_callback
A function to process output obtained from the R session via "stderr" channel
Method handle_scan()
Handle input request created by the function `scan` the in the R session
Arguments
txt
Output string containing a special readline prompt
input_callback
A function to request input from the frontend
stdout_callback
A function to process output obtained from the R session via "stdout" channel
stderr_callback
A function to process output obtained from the R session via "stderr" channel