ropensci / spelling

Tools for Spell Checking in R
https://docs.ropensci.org/spelling
Other
107 stars 25 forks source link

References count as spelling errors in spell_check_files() with Rmd #9

Closed paleolimbot closed 5 years ago

paleolimbot commented 6 years ago

When using references in RMarkdown, it looks like they count as spelling errors (also, keys and values in the YAML header show up as errors, but these are pretty easy to filter out and might even be necessary if the title field needs checking). I'd be happy to make a PR on this, but not sure what the approach should be. Maybe a user-defined filter function that can exclude certain regexes from being checked?

biblio_file <- tempfile(fileext = ".bib")
rmd_file <- tempfile(fileext = ".Rmd")

writeLines(
  paste(
    "@article{dunnington16,",
    "  title = {A geochemical perspective on the impact of development at {Alta} {Lake}, {British} {Columbia}, {Canada}},",
    "  volume = {56},",
    "  doi = {10.1007/s10933-016-9919-x},",
    "  number = {4},",
    "  journal = {Journal of Paleolimnology},",
    "  author = {Dunnington, Dewey W. and Spooner, Ian S. and White, Chris E. and Cornett, R. Jack and Williamson, Dave and Nelson, Mike},",
    "  month = nov,",
    "  year = {2016},",
    "  pages = {315-330},",
    "}",
    sep = "\n"
  ),
  biblio_file
)

writeLines(
  paste(
    "---",
    "output: word_document",
    sprintf("bibliography: %s", biblio_file),
    "---",
    "",
    "Everything @dunnington16 says is obviously correct",
    "",
    "Lakes are fantastic [@dunnington16]",
    "",
    "This Dunnington fellow really has things figured out [-@dunnington16]",
    sep = "\n"
  ),
  rmd_file
)

cat(paste(readLines(rmd_file), collapse = "\n"))
#> ---
#> output: word_document
#> bibliography: /var/folders/bq/2rcjstv90nx1_wrt8d3gqw6m0000gn/T//Rtmp95OnIv/file3d521f8518fb.bib
#> ---
#> 
#> Everything @dunnington16 says is obviously correct
#> 
#> Lakes are fantastic [@dunnington16]
#> 
#> This Dunnington fellow really has things figured out [-@dunnington16]
spelling::spell_check_files(rmd_file)
#>   WORD         FOUND IN
#> bq           file3d525b2b16e7.Rmd:2
#> dunnington   file3d525b2b16e7.Rmd:6,8,10
#> Dunnington   file3d525b2b16e7.Rmd:10
#> fb           file3d525b2b16e7.Rmd:2
#> gn           file3d525b2b16e7.Rmd:2
#> gqw          file3d525b2b16e7.Rmd:2
#> nx           file3d525b2b16e7.Rmd:2
#> OnIv         file3d525b2b16e7.Rmd:2
#> rcjstv       file3d525b2b16e7.Rmd:2
#> Rtmp         file3d525b2b16e7.Rmd:2
jeroen commented 5 years ago

Can you point me to a real world example of a markdown file with a citation bibliography?

paleolimbot commented 5 years ago

Try here: https://github.com/paleolimbot/coring-deformation (published version here: https://doi.org/10.1007/s10933-017-9947-1 )

It looks like LaTeX equations are also included in the spell checking, in addition to references.

spelling::spell_check_files("README.Rmd")
#  WORD                FOUND IN
# Acknowledgements    README.Rmd:151
# acton               README.Rmd:101,105,115
# al                  README.Rmd:101,105,183
# aubourg             README.Rmd:101
# Aubourg             README.Rmd:101
# brunschon           README.Rmd:131
# cocquyt             README.Rmd:149
# dplyr               README.Rmd:111,111
# et                  README.Rmd:101,105,183
# frac                README.Rmd:103,125,129
# funcion             README.Rmd:101
# ggplot              README.Rmd:111,111
# glew                README.Rmd:101,119
# Glew                README.Rmd:119
# guyard              README.Rmd:131
# iV                  README.Rmd:125
# kegwin              README.Rmd:101
# Kegwin              README.Rmd:101
# kylander            README.Rmd:131
# ln                  README.Rmd:103
# NSERC               README.Rmd:153
# ODP                 README.Rmd:101,105
# Oufi                README.Rmd:101
# paleolimnological   README.Rmd:2,97,107,121,143,149
# paleomagnetic       README.Rmd:101
# replicability       README.Rmd:131
# rosenbaum           README.Rmd:101,107
# stratigraphic       README.Rmd:97
# Stratigraphy        README.Rmd:93
# un                  README.Rmd:131
# wickham             README.Rmd:111
# XRF                 README.Rmd:131
jeroen commented 5 years ago

Spec: https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html