Writing S3 `head()` methods
November 27, 2023
I’ve been struggling for the past 15-20 minutes trying to fix the
following R CMD check greivances.
checking whether the namespace can be loaded with stated dependencies ... WARNING
Error: object 'head' not found whilst loading namespace 'arcgislayers'
Execution halted
checking dependencies in R code ... NOTE
Error: object 'head' not found whilst loading namespace 'arcgislayers'
It feels like something that shouldn’t be difficult? You write the
method and you export it right? Well, that’s true if the function is
exported in base. But there are a lot of handy functions that are in
base R that are not in the package {base}.
head(), the function I’m fighting with, is actually an export of the
base R package {utils}.
Here’s some code I have that I couldn’t get to export head() properly.
#' @export
{
}
To fix this we need to do the following:
- Add
utilsas an imported package withusethis::use_package("utils") - Then we need to specifically import
headby adding#' @importFrom utils head - Redocument with
devtools::document()(or cmd + shift + d)
The whole shebang:
#' @importFrom utils head
#' @export
{
}
Now R CMD check won’t complain about it.