diff --git a/Dockerfile b/Dockerfile index 3437db8..a17e33e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,8 @@ FROM rocker/r-ver:4.4.0 LABEL org.opencontainers.image.authors="CCDL ccdl@alexslemonade.org" 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 diff --git a/spell-check.R b/spell-check.R index 9b1f311..f91e69b 100644 --- a/spell-check.R +++ b/spell-check.R @@ -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