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

registerCommandStreamCallback(callback)

Arguments

callback

A function to execute when the command is invoked.

Value

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

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.

Note

The registerCommandStreamCallback function was introduced in RStudio 1.4.1589.

See also

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

Examples


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)
}