On Sat, 17 Oct 2009, Michael Friendly wrote:
Hi
Several years ago I sought & received help (thanks!) from people on
this list regarding map and data
files associated with my article, A.M. Guerry's Moral Statistics of
France: Challenges for multivariate spatial analysis,
that appeared in Statistical Science, 2007, 22,368-399. As
supplementary materials for that article, I prepared
http://www.math.yorku.ca/SCS/Gallery/guerry/
and also included map and data files for R at
http://www.math.yorku.ca/SCS/Gallery/guerry/maps.html#R
but these were really just a sketch that required more work to make
them fully usable.
Now I'd like to make an R package including the gfrance1 map and the
guerry data, and other things,
but I found that something in maptools or other packages had changed,
so that a script that worked
for me with these map files back in Aug, 2008 does so no longer:
library(sp)
library(maptools)
gfrance <- readShapeSpatial("gfrance1")
Error in read.shape(filen = fn, verbose = verbose, repair = repair) :
File size and implied file size differ, consider trying repair=TRUE
I get the same error with readShapePoly().
readShapeSpatial() is a wrapper for readShapePoly() and others,
choosing on shape type. The message suggests that the *.shx file is
not as expected.
With a freshly downloaded copy from your website, I cannot reproduce
the problem, and gfrance1.shp reads correctly on:
R version 2.10.0 (2009-10-26)
i686-pc-linux-gnu
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] maptools_0.7-26 foreign_0.8-38 sp_0.9-44
loaded via a namespace (and not attached):
[1] grid_2.10.0 lattice_0.17-26
Once I can get that sorted out, it's not exactly clear to me exactly
how to prepare map files
(SpatialPolygonsDataFrame) for a package with appropriate
documentation. Using
another version of the Guerry map and data (omitting Corsica)
provided by Stephane Dray, I *could* read it
successfully, then tried
cd("dray")
gfrance85 <- readShapePoly("gfrance1")
save(gfrance85, file="gfrance85.rda")
prompt(gfrance85)
Created file named 'gfrance85.Rd'.
Edit the file and move it to the appropriate directory.
There is no prompt method for SpatialPolygonsDataFrame objects, so
prompt() just dumps the entire results of str(gfrance85); I can of
course edit out the @ polygons list. Is this the recommended way to
include such objects in packages?
The prompt method for data either identifies data.frame objects or
dumps the object. For me,
prompt(as(gfrance, "data.frame"), name="gfrance")
looks easier to edit, adding the class details.
Hope this helps,
Roger