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

R CMD check note: not imported from lifecycle #22

Closed
florianm opened this issue Sep 23, 2019 · 8 comments
Closed

R CMD check note: not imported from lifecycle #22

florianm opened this issue Sep 23, 2019 · 8 comments

Comments

@florianm
Copy link

florianm commented Sep 23, 2019

Hi, thanks for this fantastic package!

I've ran usethis::use_lifecycle() and use the \lifecycle{...} badges in my function docs.
I'm getting a NOTE from R CMD check:

N  checking dependencies in R code (401ms)
   Namespace in Imports field not imported from: ‘lifecycle’
     All declared Imports should be used.

Related: in addition to above NOTE, goodpractice also raises #19, output see details.

What's the cleanest way to fix this NOTE?

sessionInfo and goodpractice

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 19.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8     LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ruODK_0.6.5        usethis_1.5.1.9000

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2         xmlparsedata_1.0.2 compiler_3.6.1     prettyunits_1.0.2  remotes_2.1.0      tools_3.6.1        digest_0.6.21      packrat_0.5.0     
 [9] pkgbuild_1.0.5     jsonlite_1.6       praise_1.0.0       pkgconfig_2.0.3    rlang_0.4.0        igraph_1.2.4.1     rex_1.1.2          whoami_1.3.0      
[17] cli_1.1.0          rstudioapi_0.10    curl_4.1           xfun_0.9           xopen_1.0.0        cyclocomp_1.1.0    stringr_1.4.0      knitr_1.25        
[25] withr_2.1.2        httr_1.4.1         xml2_1.2.2         desc_1.2.0         fs_1.3.1           rprojroot_1.3-2    glue_1.3.1         R6_2.4.0          
[33] processx_3.4.1     rcmdcheck_1.3.3    callr_3.3.2        lintr_1.0.3        covr_3.3.1         magrittr_1.5       backports_1.1.4    ps_1.3.0          
[41] clisymbols_1.2.0   assertthat_0.2.1   goodpractice_1.0.2 stringi_1.4.3      lazyeval_0.2.2     crayon_1.3.4      

Output from goodpractice::goodpractice():

── GP ruODK ───────────────────────────────

It is good practice tofix this R CMD check NOTE: Namespace in Imports field not imported from:lifecycleAll declared Imports should be used.
────────────────────────────────────────
There were 43 warnings (use warnings() to see them)

warnings()
# brings one of these per use of \lifecycle{} macro
In parse_Rd("/home/florian/projects/ruODK/man/yell_if_missing.Rd",  ... :
  /home/florian/projects/ruODK/man/yell_if_missing.Rd:21: unknown macro '\lifecycle'
> 
@lionel-
Copy link
Member

lionel- commented Sep 23, 2019

I'm not sure if there is a conventional way to fix this NOTE but including something like this somewhere in the package should do it:

if (FALSE) lifecycle::deprecate_soft()

@florianm
Copy link
Author

florianm commented Sep 23, 2019

@lionel- Thanks for the quick turnaround, this worked!

Including if (FALSE) lifecycle::deprecate_soft() in a file underneath R/ removes the CMD check NOTE.
To preserve test coverage, this file is excluded via codecov.yml.
usethis could maybe generate such a file automatically on usethis::use_lifecycle() (feature request r-lib/usethis#896).

@jennybc
Copy link
Member

jennybc commented Sep 23, 2019

Two more "traditional" ways to silence this are to import one function into your NAMESPACE. This is what the tidyverse package does:

https://github.com/tidyverse/tidyverse/blob/62710238560b04ea2a9fe3f3cc70ceede5aa4273/R/tidyverse.R#L4-L23

Or you can create a pragmatic function that uses something from the package, but never call it:

https://github.com/tidyverse/googledrive/blob/050a982cba630503702bdde05a77d727baa36d48/R/googledrive-package.R#L36-L44

@florianm
Copy link
Author

Thanks @jennybc, that's neat!

Side note: I've been looking for %||% way longer than I wish to admit.

@jimhester
Copy link
Member

You don't even need the if or an actual call, e.g. just this somewhere in your package would work.

lifecycle::deprecate_soft

@florianm
Copy link
Author

Thanks @jimhester!

I've moved the lifecycle dependency to "Suggests" (together with my other dev dependencies like testthat, usethis, covr) which muted the original NOTE. I'm still happily using the lifecycle badges in function docs.

Is "Suggests" the correct place for lifecycle if using its badges?

@lionel-
Copy link
Member

lionel- commented Sep 26, 2019

It won't cause R CMD check problems but it will cause trouble at doc rendering time when your users don't have lifecycle installed. I think it has to be in imports.

@pvelayudhan
Copy link

Sorry to comment on an old closed issue but found this while trying to answer the same question (what to do when just using lifecycle badges). It does seem that currently the lifecycle documentation does have a paragraph addressing this exact scenario:

lifecycle::badge() is run by roxygen at build time so you don’t need to add lifecycle to Imports: just to use the badges. However, it’s still good practice to add to Suggests: so that it will be available to package developers

(from https://cran.r-project.org/web/packages/lifecycle/lifecycle.pdf)

So no secret lifecycle function calls or Imports addition needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants