-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for spell checking roxygen comments
`roxygen2::parse_file()` parses the roxygen comments in each file. Text from relevant tags is then searched for spelling errors with `hunspell::hunspell()` to find misspelled words. Because roxygen does not store the original positions of parsed tags we then need to find the misspelled word locations in the original roxygen comment lines of the source. This is done by `find_word_positions()`.
- Loading branch information
Showing
11 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
find_word_positions <- function(lines, words) { | ||
.Call(`_spelling_find_word_positions`, lines, words) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.o | ||
*.so | ||
*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
#include <Rcpp.h> | ||
|
||
using namespace Rcpp; | ||
|
||
// find_word_positions | ||
Rcpp::DataFrame find_word_positions(CharacterVector lines, CharacterVector words); | ||
RcppExport SEXP _spelling_find_word_positions(SEXP linesSEXP, SEXP wordsSEXP) { | ||
BEGIN_RCPP | ||
Rcpp::RObject rcpp_result_gen; | ||
Rcpp::RNGScope rcpp_rngScope_gen; | ||
Rcpp::traits::input_parameter< CharacterVector >::type lines(linesSEXP); | ||
Rcpp::traits::input_parameter< CharacterVector >::type words(wordsSEXP); | ||
rcpp_result_gen = Rcpp::wrap(find_word_positions(lines, words)); | ||
return rcpp_result_gen; | ||
END_RCPP | ||
} | ||
|
||
static const R_CallMethodDef CallEntries[] = { | ||
{"_spelling_find_word_positions", (DL_FUNC) &_spelling_find_word_positions, 2}, | ||
{NULL, NULL, 0} | ||
}; | ||
|
||
RcppExport void R_init_spelling(DllInfo *dll) { | ||
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); | ||
R_useDynamicSymbols(dll, FALSE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <Rcpp.h> | ||
#include <cstring> | ||
using namespace Rcpp; | ||
|
||
// [[Rcpp::export]] | ||
Rcpp::DataFrame find_word_positions(CharacterVector lines, | ||
CharacterVector words) { | ||
std::vector<const char*> found_words; | ||
std::vector<int> found_lines; | ||
std::vector<int> found_starts; | ||
|
||
for (int i = 0; i < words.size(); ++i) { | ||
const char* word = words.at(i); | ||
size_t len = strlen(word); | ||
bool found = false; | ||
for (int j = 0; j < lines.size(); ++j) { | ||
const char* line = lines.at(j); | ||
for (const char* p = line; (p = strstr(p, word)) != NULL; ++p) { | ||
if ((p == line) || (p != NULL && !isalnum(p[-1]))) { | ||
if (!isalnum(p[len])) { | ||
found = true; | ||
found_words.push_back(word); | ||
found_lines.push_back(j + 1); | ||
found_starts.push_back((int)(p - lines.at(j)) + 1); | ||
} | ||
p += len; | ||
} | ||
} | ||
} | ||
if (!found) { | ||
found_words.push_back(word); | ||
found_lines.push_back(NA_INTEGER); | ||
found_starts.push_back(NA_INTEGER); | ||
} | ||
} | ||
return DataFrame::create(_["word"] = found_words, _["line"] = found_lines, | ||
_["start"] = found_starts, | ||
Rcpp::_["stringsAsFactors"] = false); | ||
} |