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

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Wed Jan 19 11:34:38 CET 2022


On 18/01/2022 5:02 p.m., Rolf Turner wrote:
> On Tue, 18 Jan 2022 10:03:09 +0100
> Aurélie Siberchicot <aurelie.siberchicot using univ-lyon1.fr> wrote:
> 
>> Thank you Andrew !
>> I think I didn't explain my context correctly.
>> I'm not importing datasets from 'sp'. I have datasets that are built
>> from S4 objects of sp.
>> In pratical terms, I don't import anything from 'sp' but I need 'sp'
>> for my datasets to exist.
> 
> I'm probably misunderstanding/missing the point --- but it seems to me
> that the obvious procedure would be to obtain the necessary objects
> from sp, build your data sets, put them into the data directory of your
> package, and then make no further reference to sp (other than perhaps
> duly acknowledging the provenance of your data sets in the help files
> that you write for them).
> 
> If my comment is totally out to lunch, please ignore it.

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



More information about the R-package-devel mailing list