registerCommandStreamCallback: Register Command Stream Callback

View source: R/commands.R

registerCommandStreamCallbackR Documentation

Register Command Stream Callback

Description

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

Usage

registerCommandStreamCallback(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.

Value

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

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


## Not run: 
# 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)

## End(Not run)

rstudioapi documentation built on Oct. 23, 2024, 1:07 a.m.