Skip to content
Prev 7638 / 12125 Next

[R-pkg-devel] package with datasets requiring sp

On 18/01/2022 5:02 p.m., Rolf Turner wrote:
The issue is that the data sets are S4 objects whose class definition is 
in sp.  You can't load such an object without having the class 
definition available.  Copying the class definition to another package 
would not be a reasonable solution.

R's check code doesn't recognize that using a class from another package 
is a hard reference to the other package, and it complains if sp is 
listed in the Imports list.

Really it should be equivalent to having a package in the Imports list, 
with all imports done using :: at runtime.  Then ade4 couldn't be 
installed without having sp present, and loading the data could trigger 
a namespace load of sp.  But that logic isn't in place.

The solution given by Prof. Ripley allows a workaround:  list sp in 
Suggests, and have a script that checks for sp before trying to load the 
data.  This is fine if loading that dataset is optional, with most users 
not needing it.  However, if it happens to be a dataset that most users 
will need to load, it's not good:  most users will need sp, and it 
should be a hard dependency for the package.

Duncan Murdoch