| showEditSuggestion {rstudioapi} | R Documentation |
Show an Edit Suggestion in RStudio
Description
Displays an edit suggestion for a specified range in the active document. The suggestion shows what text would replace the given range. RStudio computes and displays the necessary insertions and deletions.
Usage
showEditSuggestion(range, text, id = NULL)
Arguments
range |
A document range (or object coercible to a range) indicating
where the suggestion applies. Can be a |
text |
Character string containing the suggested replacement text for the specified range. |
id |
The document id. When |
Details
The edit suggestion appears in the RStudio editor, showing what would change if the suggestion were accepted. Users can accept or dismiss the suggestion through RStudio's UI.
The range parameter specifies the region of text that would be replaced.
RStudio automatically computes the minimal diff between the current text in
that range and the suggested text.
Value
Invisibly returns TRUE if the suggestion was successfully shown,
FALSE otherwise.
Note
The showEditSuggestion function was added in version 2026.01.0
of RStudio.
See Also
setGhostText for inline completion suggestions,
insertText for direct text insertion,
modifyRange for programmatic range modification.
Examples
## Not run:
# Suggest replacing a word
range <- document_range(c(5, 1), c(5, 10))
showEditSuggestion(range, "corrected_text")
# Using vector notation
showEditSuggestion(c(5, 1, 5, 10), "corrected_text")
# Suggest for current selection
context <- getActiveDocumentContext()
selection <- primary_selection(context)
showEditSuggestion(selection$range, "improved code")
## End(Not run)