R CMD check

Mini-Lecture 16

Ben Baumer

Smith College

2024-10-29

Slack review

Dependencies

I’m still a bit unsure about dependencies. When and where do we have to import functions and when can we call libraries in the script?

  • Use library() in scripts:
    • in data-raw/
  • Use :: or @importFrom in package code:
    • in R/
    • add these packages to Imports

Dependencies (cont’d)

I’m still a bit unsure about dependencies. When and where do we have to import functions and when can we call libraries in the script?

  • Use requireNamespace() in documentation code:
    • in vignettes/
    • in @examples
    • in tests/
    • add these packages to Suggests
  • Don’t confuse Imports section of DESCRIPTION with import() directive in NAMESPACE

.Rbuildignore

I got lost on explaining .Rbuildignore.

^.*\.Rproj$         # Automatically added by RStudio,
^\.Rproj\.user$     # used for temporary files. 
^README\.Rmd$       # An Rmarkdown file used to generate README.md
^cran-comments\.md$ # Comments for CRAN submission
^NEWS\.md$          # A news file written in Markdown

R CMD check

What is R CMD check?

  • Runs over 50 automated checks
  • Three types of problems:
    • Errors: must fix
    • Warnings: should really fix
    • Notes: should probably fix
  • READ the error messages
    • Look them up in the book
    • Most won’t mean much until it happens to you
  • Reach out with #questions

Errors you are likely to see

  • Checking installed package size…
    • CRAN packages limited to 5 MB
  • Checking package dependencies…
  • Checking dependencies in R code…
    • Anything you use must appear in DESCRIPTION somewhere
    • Depends: probably do not use
    • Imports: dependencies in package
    • Suggests: packages used only in examples or vignettes

Errors you are likely to see

  • Checking examples…
    • examples code has to run
    • can’t take too long
  • Checking tests…
    • have to pass all tests
  • Checking Rd sections…
    • have to document all exported functions
    • have to document all arguments
    • use @rdname to document multiple functions together

Example: macleish package

  • Let’s take a quick tour!

Now

Homework