When performing spell checking on source documents, we may need to skip R
code chunks and inline R expressions, because many R functions and symbols
are likely to be identified as typos. This function is designed for the
filter
argument of aspell()
to filter out code chunks
and inline expressions.
knit_filter(ifile, encoding = "UTF-8")
A character vector of the file content, excluding code chunks and inline expressions.
library(knitr)
knitr_example = function(...) system.file("examples", ..., package = "knitr")
# \donttest{
if (Sys.which("aspell") != "") {
# -t means the TeX mode
utils::aspell(knitr_example("knitr-minimal.Rnw"), knit_filter, control = "-t")
# -H is the HTML mode
utils::aspell(knitr_example("knitr-minimal.Rmd"), knit_filter, control = "-H -t")
}
#> LaTeX
#> /tmp/RtmpJBYlpe/temp_libpath18dc9a6c8337b8/knitr/examples/knitr-minimal.Rmd:38:1
#>
#> knitr
#> /tmp/RtmpJBYlpe/temp_libpath18dc9a6c8337b8/knitr/examples/knitr-minimal.Rmd:3:38
#> /tmp/RtmpJBYlpe/temp_libpath18dc9a6c8337b8/knitr/examples/knitr-minimal.Rmd:59:42
# }