0

I have refactored my package to remove any trace of raster to replace it with the newer, faster terra package. Here is the list of functions and packages I now import as listed in my package's NAMESPACE file:

# Generated by roxygen2: do not edit by hand
export(calc_areas)
import(PolynomF)
import(dplyr)
import(ggplot2)
import(sjPlot)
importFrom(grDevices,dev.off)
importFrom(grDevices,png)
importFrom(sf,st_as_sf)
importFrom(sf,st_crs)
importFrom(stats,lm)
importFrom(terra,aggregate)
importFrom(terra,as.data.frame)
importFrom(terra,cellSize)
importFrom(terra,classify)
importFrom(terra,crop)
importFrom(terra,ext)
importFrom(terra,extract)
importFrom(terra,mask)
importFrom(terra,minmax)
importFrom(terra,rast)
importFrom(terra,values)
importFrom(terra,vect)
importFrom(utils,write.csv)

The problem is that when I run devtools::document(), I still get the raster and sp packages attached.

devtools::document()
i Updating pkgname documentation
i Loading pkgname
Writing NAMESPACE
Loading required package: raster
Loading required package: sp

Attaching package: ‘raster’

The following object is masked from ‘package:pkgname’:

    select

Writing NAMESPACE

I don't use these two packages anywhere in my code (i.e. raster and sp). What's then happening here?

I don't want to add them in my imports' list not knowing where they are used. Besides, if I do, then my package won't pass the CRAN checks. Please help me.

3
  • I've just created a minimal package with one function that has @importFrom and @import directives that give me the same NAMESPACE file but I don't see this message about sp and raster. If you can't share your package code I suggest you subtract things until the message disappears or start from zero and add until it appears.
    – Spacedman
    Feb 5, 2022 at 12:00
  • 1
    @Spacedman You inspired me to set up another mock package containing only the function that seemed to have issues. It turns out these packages were being used by the data I was using in my examples and tests. I didn't know one needs to import packages used to create the data objects as well. I am noob; so yeah, that's yet another new thing I just learned. Hurrah! Feb 6, 2022 at 10:20
  • Suggest you write your solution as an answer here in case anyone else hits the same problem!
    – Spacedman
    Feb 6, 2022 at 10:22

1 Answer 1

0

I figured out the origin of the issue. When you use datasets in your package (e.g. as part of examples or tests), the packages that define the classes used by the objects in your data need to be attached as well. You therefore have to import these packages when you are documenting your datasets in the data.R file. Let's hope this clarification helps someone out there who would be as confused as I was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.