Learn R Programming

rstudioapi (version 0.16.0)

registerCommandStreamCallback: Register Command Stream Callback

Description

Registers a callback to be executed whenever any RStudio command is invoked.

Usage

registerCommandStreamCallback(callback)

Value

A handle representing the registration. Pass this handle to unregisterCommandCallback to unregister the callback.

Arguments

callback

A function to execute when the command is invoked.

Details

The callback function will be given a single argument with the ID of the command that was invoked. See the RStudio Server Professional Administration Guide appendix for a list of command IDs.

Note that there is a small performance penalty incurred across the IDE when a command stream listener is present. If you only need to listen to a few specific commands, it is recommended to set up callbacks for them individually using registerCommandCallback.

See Also

unregisterCommandCallback to unregister the callback, and registerCommandCallback to be notified whenever a specific command is executed.

Examples

Run this code

if (FALSE) {
# Set up a callback to print the ID of commands executed to the console.
handle <- rstudioapi::registerCommandStreamCallback(function(id) {
  message("Command executed: ", id)
})

# Later: Unregister the callback
rstudioapi::unregisterCommandCallback(handle)
}

Run the code above in your browser using DataLab