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

Include paths in output TSV #18

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('spelling', 'readr', 'purrr', 'dplyr', 'tidyr'))"
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

# add spell check script and make it executable
COPY spell-check.R /spell-check.R
Expand Down
26 changes: 21 additions & 5 deletions spell-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,27 @@ 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
all_paths <- files |>
dirname() |>
unique()
sjspielman marked this conversation as resolved.
Show resolved Hide resolved


# check spelling for all files in each path, and prepend the file path
# to the file name in the final data frame
spelling_errors <- all_paths |>
purrr::map(
\(path) {
list.files(path = path, pattern = file_pattern) |>
spelling::spell_check_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
Loading