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.
Arguments
- range
A document range (or object coercible to a range) indicating where the suggestion applies. Can be a
document_rangeobject or a numeric vector of the formc(start_row, start_col, end_row, end_col).- text
Character string containing the suggested replacement text for the specified range.
- id
The document id. When
NULLor blank, the suggestion will be shown in the currently open, or last focused, RStudio document.
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.
See also
setGhostText for inline completion suggestions,
insertText for direct text insertion,
modifyRange for programmatic range modification.
Examples
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")
} # }