library vs :: How to load packages into a package

Not something I totally understand, but when making my first package I found that the package build check would throw warnings if I didn't use the :: approach, iirc. In theory you don't always need it: try reading the Namespaces page in the R Packages book, in particular this section on imports.

Summary: You shouldn't ever use library() in a package, but you may use @importFrom pkg fun and this should avoid the need for ::

PS If you're not really building a package, but more just a collection of scripts for your own use, then you can do what you want as along as you're willing to ignore error messages if you check or try to build the project. It's a nice challenge, imho, to actually turn it into a valid package though - I found it a frustrating but ultimately valuable learning journey. You might also be interested in this other topic I started.

2 Likes