R/chk_spelling.R

Defines functions spelling_positions

#' @include lists.R

#' @noRd
spelling_positions <- function(word, locations) {
  unlist(lapply(locations, function(loc) {
    parts <- strsplit(loc, ":")[[1]]
    line_nums <- as.integer(strsplit(parts[2], ",")[[1]])
    lapply(line_nums, function(ln) {
      check_position(parts[1], ln, line = word)
    })
  }), recursive = FALSE)
}

CHECKS$spelling <- make_check(

  description = "No misspelled words in documentation",
  tags = c("info", "documentation"),
  preps = "spelling",

  gp = paste(
    "fix spelling errors in package documentation.",
    "Use {.code spelling::spell_check_package()} to review misspelled words",
    "and add false positives to {.file inst/WORDLIST}."
  ),

  check = function(state) {
    if (identical(state$spelling, "no_wordlist") ||
        inherits(state$spelling, "try-error")) {
      return(na_result())
    }

    res <- state$spelling
    if (nrow(res) == 0) {
      return(check_result(TRUE))
    }

    positions <- unlist(
      Map(spelling_positions, res$word, res$found),
      recursive = FALSE
    )
    check_result(FALSE, positions)
  }
)

Try the goodpractice package in your browser

Any scripts or data that you put into this service are public.

goodpractice documentation built on June 5, 2026, 5:06 p.m.