usethis icon indicating copy to clipboard operation
usethis copied to clipboard

Don't need to import base packages

Open hadley opened this issue 2 months ago • 5 comments

hadley avatar Sep 29 '25 13:09 hadley

This definitely contradicts a "rule" I've internalized. Have I truly been confused about this? Or did something change? I think we might need to change some wording in R Packages as well, if this is really the situation.

jennybc avatar Sep 30 '25 16:09 jennybc

I don't think anything has changed 😬

hadley avatar Sep 30 '25 17:09 hadley

FWIW here are the existing base packages which list other base packages in Imports:

# A tibble: 16 × 2
   Package  imported_pkg
   <chr>    <chr>       
 1 graphics grDevices   
 2 grid     grDevices   
 3 grid     utils       
 4 methods  stats       
 5 methods  utils       
 6 parallel compiler    
 7 parallel tools       
 8 splines  graphics    
 9 splines  stats       
10 stats    grDevices   
11 stats    graphics    
12 stats    utils       
13 stats4   graphics    
14 stats4   methods     
15 stats4   stats       
16 tcltk    utils   

And in WRE I see:

The Imports field lists packages whose namespaces are imported from (as specified in the NAMESPACE file) but which do not need to be attached. Namespaces accessed by the ::’ and :::’ operators must be listed here, or in Suggests or Enhances (see below). Ideally this field will include all the standard packages that are used ...

So I'm thinking this is still a best practice (?).

jennybc avatar Sep 30 '25 17:09 jennybc

While I'm at it, here's a taste of how much tidyverse/r-lib package do this (TL;DR usethis is not alone):

# A tibble: 44 × 4
   Package     organization base_imports_count base_imports                   
   <chr>       <chr>                     <int> <chr>                          
 1 bit64       r-lib                         4 graphics, methods, stats, utils
 2 remotes     r-lib                         4 methods, stats, tools, utils   
 3 crayon      r-lib                         3 grDevices, methods, utils      
 4 devtools    r-lib                         3 stats, tools, utils            
 5 systemfonts r-lib                         3 grid, tools, utils             
 6 usethis     r-lib                         3 stats, tools, utils            
 7 ggplot2     tidyverse                     3 grDevices, grid, stats         
 8 gargle      r-lib                         2 stats, utils                   
 9 gtable      r-lib                         2 grid, stats                    
10 isoband     r-lib                         2 grid, utils 
...

I know this is a small change, but would require a pretty significant change inside my brain if we're going to say base packages shouldn't appear in Imports.

jennybc avatar Sep 30 '25 18:09 jennybc

A better question would be which tidyverse package don't import all the base packages that they use. Which I bet is a lot.

hadley avatar Sep 30 '25 19:09 hadley