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.
showEditSuggestion(range, text, id = NULL)A document range (or object coercible to a range) indicating
where the suggestion applies. Can be a document_range object or
a numeric vector of the form c(start_row, start_col, end_row, end_col).
Character string containing the suggested replacement text for the specified range.
The document id. When NULL or blank, the suggestion will
be shown in the currently open, or last focused, RStudio document.
Invisibly returns TRUE if the suggestion was successfully shown,
FALSE otherwise.
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.
The showEditSuggestion function was added in version 2026.01.0
of RStudio.
setGhostText for inline completion suggestions,
insertText for direct text insertion,
modifyRange for programmatic range modification.
if (FALSE) { # \dontrun{
# 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")
} # }