Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up testthat in analysis repos, and spell check as an example #258

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Create test-spelling.R
  • Loading branch information
kelliemac authored Jan 11, 2025
commit 16891362143858608874973e03dad0ef0bac2ff7
29 changes: 29 additions & 0 deletions inst/templates/test-spelling.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# save as, for example, tests/testthat/test-spelling.R

library(testthat)
library(spelling)

test_that("All Rmd files are free of spelling errors", {
# Define the path to the Rmd files
rmd_files <- list.files(path = ".", pattern = "\\.Rmd$", full.names = TRUE, recursive = TRUE)

# Define custom wordlist
custom_wordlist <- system.file("templates", WORDLIST, package = "VISCtemplates") # can update to use a project-specific wordlist instead
if (file.exists(custom_wordlist)) {
ignore_words <- readLines(custom_wordlist)
} else {
ignore_words <- character(0)
}

# Perform spell check on each Rmd file
for (file in rmd_files) {
spelling_errors <- spell_check_files(file, ignore = ignore_words, lang = "en_US")
if (length(spelling_errors$word) > 0) {
error_message <- paste("Spelling errors found in file:", file, "\n",
paste(spelling_errors$word, collapse = ", "))
fail(error_message)
}
}

expect_true(length(spelling_errors$word) == 0, info = "No spelling errors found in any Rmd files.")
})