Convincing R that the .dbf file associated with a .shp file is not an executable during command checks

Viewed 135

I am working on submitting an R package to CRAN. Right now I am trying to reduce the memory footprint of the package. Because this package deals with spatial data that has a very particular format, I want to include a properly formatted shapefile as an example. If I include the full-size original shapefile, there are no warnings (other than file size) in the R CMD checks. However, if I crop the file and include the cropped version in the package (in "inst/extdata") I get this warning:

W  checking for executable files (389ms)
   Found the following executable file:
     inst/extdata/temp/temp.dbf
   Source packages should not contain undeclared executable files.
   See section ‘Package structure’ in the ‘Writing R Extensions’ manual.

This file is the database file associated with the shapefile. I have tried cropping the file and saving it using rgdal functions, sf functions, and using QGIS. I have also verified that the modes of the cropped files match the original file using chmod. I even tried changing .dbf to .DBF. Does anyone have any additional suggestions, other than listing it in BinaryFiles, which CRAN will not accept in a submission?

I'm running R version 4.0.2 via RStudio 2021.09.1 on Mac OSX 10.15.7. rgdal and sf are fully updated, as are all of their dependencies.

1 Answers

This is a known issue[1] where file will mis-identify DBF files with last-update date in the year 2022. Easiest fix is to not use a 2022 update date when saving the file. Alternatively you can simply change the second byte of the file after the fact, e.g.:

fn = "myfile.dbf"
sz = file.info(fn)$size
r = readBin(fn, raw(), sz)
r[2] = as.raw(121) ## make it 2021 instead of 2022
writeBin(r, fn)

(See also corresponding discussion on R-package-devel)

Related