ropensci/spelling

Warnings when spell-checking a package with Rd macros

wlandau opened this issue · 9 comments

The lifecycle package does define the \lifecycle macro, but spelling warns that it is not defined.

git2r::clone(
  url = "https://github.com/r-lib/lifecycle",
  local_path = "lifecycle"
)
#> cloning into 'lifecycle'...
#> Receiving objects:   1% (9/880),   13 kb
#> Receiving objects:  11% (97/880),   30 kb
#> Receiving objects:  21% (185/880),   94 kb
#> Receiving objects:  31% (273/880),  111 kb
#> Receiving objects:  41% (361/880),  134 kb
#> Receiving objects:  51% (449/880),  150 kb
#> Receiving objects:  61% (537/880),  166 kb
#> Receiving objects:  71% (625/880),  166 kb
#> Receiving objects:  81% (713/880),  183 kb
#> Receiving objects:  91% (801/880),  191 kb
#> Receiving objects: 100% (880/880),  239 kb, done.
#> Local:    master /tmp/RtmpRWoEuz/reprex85671d073af/lifecycle
#> Remote:   master @ origin (https://github.com/r-lib/lifecycle)
#> Head:     [445f7f6] 2019-08-09: Add `is_present()` (#15)
spelling::spell_check_package("lifecycle")
#> DESCRIPTION does not contain 'Language' field. Defaulting to 'en-US'.
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:47: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:48: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:49: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:50: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:51: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:52: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:53: unknown macro
#> '\lifecycle'
#> Warning in parse_Rd(ifile, encoding = encoding, macros = macros): /tmp/
#> RtmpRWoEuz/reprex85671d073af/lifecycle/man/badge.Rd:54: unknown macro
#> '\lifecycle'
#>   WORD               FOUND IN
#> backtrace          last_warnings.Rd:14,22,23
#>                    NEWS.md:13
#> backtraces         NEWS.md:13
#>                    lifecycle.Rmd:155,198
#> behaviour          deprecate_soft.Rd:68
#>                    lifecycle.Rmd:38,40,42
#> Codecov            README.md:6
#> conjuction         lifecycle.Rmd:198
#> invokation         lifecycle.Rmd:85
#> programmatically   deprecate_soft.Rd:38
#> questining         README.md:27
#>                    lifecycle.Rmd:23
#> rlang's            NEWS.md:30
#> signalled          lifecycle-package.Rd:16
#>                    description:8
#> signaller          NEWS.md:18,24
#> summarised         lifecycle.Rmd:32
#> testthat           deprecate_soft.Rd:43
#>                    verbosity.Rd:11
#>                    lifecycle.Rmd:83
#> ther               lifecycle.Rmd:83

Created on 2019-08-16 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.0 (2019-04-26)
#>  os       Ubuntu 18.04.2 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-08-16                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.6.0)                
#>  callr         3.3.1      2019-07-18 [1] CRAN (R 3.6.0)                
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                
#>  commonmark    1.7        2018-12-01 [1] CRAN (R 3.6.0)                
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                
#>  devtools      2.1.0      2019-07-06 [1] CRAN (R 3.6.0)                
#>  digest        0.6.20     2019-07-04 [1] CRAN (R 3.6.0)                
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                
#>  git2r         0.26.1     2019-06-29 [1] CRAN (R 3.6.0)                
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.0)                
#>  hunspell      3.0        2018-12-15 [1] CRAN (R 3.6.0)                
#>  knitr         1.24       2019-08-08 [1] CRAN (R 3.6.0)                
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                
#>  pkgbuild      1.0.4      2019-08-05 [1] CRAN (R 3.6.0)                
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)                
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.0)                
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                
#>  Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.6.0)                
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                
#>  rlang         0.4.0      2019-06-25 [1] CRAN (R 3.6.0)                
#>  rmarkdown     1.14       2019-07-12 [1] CRAN (R 3.6.0)                
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                
#>  spelling      2.1        2019-03-11 [1] CRAN (R 3.6.0)                
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                
#>  testthat      2.2.1      2019-07-25 [1] CRAN (R 3.6.0)                
#>  usethis       1.5.1.9000 2019-08-11 [1] Github (r-lib/usethis@b241420)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                
#>  xfun          0.8        2019-06-25 [1] CRAN (R 3.6.0)                
#>  xml2          1.2.2      2019-08-09 [1] CRAN (R 3.6.0)                
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                
#> 
#> [1] /home/landau/R/R-3.6.0/library

This seems to arise in tools::parse_Rd ...

Could spelling use parse_Rd with flag permissive?

tools::parse_Rd(permissive=TRUE): Logical indicating that unrecognized macros should be treated as text with no warning.

Source https://www.rdocumentation.org/packages/tools/versions/3.6.1/topics/parse_Rd

Does that fix it? Can you send a PR?

I was just reading the spelling code, and can't find where spelling uses parse_Rd... closest I got was

tools::RdTextFilter() defaults to use macros = file.path(R.home("share"), "Rd", "macros", "system.Rd") - does lifecycle install its macros into those or does macros need to include lifecycle's macro install location? Whose responsibility is that, spelling or lifecycle?

tools::RdTextFilter() should load the package macros as well, ideally, by default. Short of that, spelling could explicitly pass on the package macros. Not trivial how to do it, but the tools package has some helper functions to do this the correct way. I'll do a PR in a minute.

Can we just use this?

tools::RdTextFilter(tools::parse_Rd(rdfile, permissive = TRUE)) 

You could, but then these macros will be treated as text, which might cause further problems. It is easier to just load the macros.

What is the status of this issue because I am still receiving this error using the current version of spelling.

Same here