[R-pkg-devel] Problem with package containing spatial data

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Feb 9 11:11:10 CET 2023


On 09/02/2023 3:56 a.m., Ivan Krylov wrote:
> В Wed, 8 Feb 2023 11:32:36 -0300
> Igor L <igorlaltuf using gmail.com> пишет:
> 
>> spatial_aisp <- sf::st_read('data-raw/shp_aisp/lm_aisp_2019.shp')
>>
>> plot(spatial_aisp) # works
>>
>> # Same data from .rda file after use usethis::use_data(spatial_aisp,
>> overwrite = TRUE)
>>
>> x <- ispdata::spatial_aisp
>>
>> plot(x) # do not work
> 
> Does this break in a new R session, but start working when you load the
> sf namespace? I think that your package needs to depend on sf in order
> for this to work. Specifying it in Imports may be enough to make the
> plot.sf S3 method available to the user.

Specifying a package in the Imports field of DESCRIPTION guarantees that 
it will be available to load, but doesn't load it.  Importing something 
from it via the NAMESPACE triggers a load, as does executing code like 
pkg::fn, or explicitly calling loadNamespace("pkg"), or loading a 
package that does one of these things.


> You may encounter other problems if you go this way, like R CMD check
> complaining that you don't use the package you're importing. Loading
> the data from a file on demand would also load the sf namespace and
> thus solve the problem.

Workarounds for the check complaints are discussed here, among other 
places:  https://stackoverflow.com/a/75384338/2554330 .

Duncan Murdoch



More information about the R-package-devel mailing list