Skip to content

Commit

Permalink
Merge pull request #18 from AlexsLemonade/sjspielman/17-include-paths
Browse files Browse the repository at this point in the history
Include paths in output TSV
  • Loading branch information
sjspielman authored Jun 6, 2024
2 parents c0e15e6 + 309cc12 commit f293333
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM rocker/r-ver:4.4.0
LABEL org.opencontainers.image.authors="CCDL [email protected]"
LABEL org.opencontainers.image.source="https://github.com/AlexsLemonade/spellcheck/tree/main"

# install the spelling and tidyr packages from CRAN
RUN Rscript -e "install.packages(c('readr', 'spelling', 'tidyr'))"
# install R package dependencies from CRAN
RUN Rscript -e "install.packages(c('dplyr', 'purrr', 'readr', 'spelling', 'tidyr'))"

# add spell check script and make it executable
COPY spell-check.R /spell-check.R
Expand Down
23 changes: 18 additions & 5 deletions spell-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@ if (file.exists(dict_file)) {
dictionary <- ""
}

# Run spell check
spelling_errors <- spelling::spell_check_files(files, ignore = dictionary) |>
data.frame() |>
tidyr::unnest(cols = found) |>
tidyr::separate(found, into = c("file", "lines"), sep = ":")

# Separate files into path groups
file_list <- split(files, dirname(files))


# check spelling for all files in each path, and prepend the file path
# to the file name in the final data frame
spelling_errors <- file_list |>
purrr::imap(
\(files, path) {
spelling::spell_check_files(files, ignore = dictionary) |>
data.frame() |>
tidyr::unnest(cols = found) |>
tidyr::separate(found, into = c("file", "lines"), sep = ":") |>
dplyr::mutate(file = file.path(path, file))
}
) |>
dplyr::bind_rows()


# Save spelling errors to file
Expand Down

0 comments on commit f293333

Please sign in to comment.