Description Usage Arguments Details Value Examples
View source: R/check_spelling.R
This function performs spell-checking on input text. It can provide a list of errors and probable correct spellings, as well as returning the input text with all errors corrected.
1 | check_spelling(inputText, mode, customSpellingList)
|
inputText |
A character string or vector of character strings |
mode |
This defines the mode of operation. Options include "output", "replace", or "both". See Details below. |
customSpellingList |
(Optional argument) If provided, the function will use this list to correct spelling errors. Must be in the same format as the result of "output" mode, and only works in "replace" mode. |
This function has three modes:
In the "output" mode, a dataframe is produced with three columns: the spelling errors present in the input text, how frequently they appear, and the most likely correct spelling for each word. A frequency graph is also plotted.
In the "replace" mode, a character string (or vector of character strings) is produced, where all of the spelling errors identified are replaced by their most likely correct spelling.
When customSpellingList = TRUE
, the "replace" mode will only correct words in the provided list
In the "both" mode, both of the above results will be produced (i.e. a list containing a dataframe of errors and suggestions, as well as the text with corrected spellings)
As a warning, this function is particularly slow, and make take a significantly long time on a sizeable vector of character strings.
A dataframe (mode="output"
), a character string or vector of character strings (mode="replace"
), or a two-object list containing both results (mode="both"
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | myString = "I went to the stroe and bought some egggs for a good porce!"
spell_check_results = check_spelling(myString, mode = "output")
spell_check_results
# error freq suggested_correction
# egggs 1 eggs
# stroe 1 store
# porce 1 pore
spell_correction_results = check_spelling(myString, mode = "replace")
spell_correction_results
# "I went to the store and bought some eggs for a good pore!"
error = c("egggs", "stroe", "porce")
suggested_correction = c("eggs", "store", "price")
my_corrections = data.frame(error=error, suggested_correction = suggested_correction)
correction_results = check_spelling(myString, mode = "replace", customSpellingList = my_corrections)
correction_results
# "I went to the store and bought some eggs for a good price!"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.