[R-sig-Geo] Guerry data: making a package

Michael Friendly friendly at yorku.ca
Fri Oct 30 17:42:27 CET 2009


Thanks, Roger

I was able to sort out my problems with reading the Guerry data/map with 
the help of Stephane Dray.
There is now an R-Forge project, Guerry, containing what we have 
assembled so far.
https://r-forge.r-project.org/projects/guerry/

In the .Rd files for the SpatialPolygonsDataFrames, gfrance & gfrance85 
included in the package, I
note that no PROJ4 information is provided, because we weren't sure 
exactly what to specify.

On my web page, I noted that you had earlier suggested
The projection here seems to be France ED50 EuroLambert, Lambert Conic 
Conformal with parameters set for continental France. Roger says: In 
PROJ.4 this is:

+proj=lcc +lat_1=46.8 +lat_0=46.8
+lon_0=2.337229166666667 +k_0=0.99987742 +x_0=600000 +y_0=2200000
+ellps=intl +units=m 

Given that:

 > slot(gfrance,"proj4string")
CRS arguments: NA

what can I specify to make this more spatial-friendly in a package?  I 
don't know what a lot of
that stuff means, but if I'm creating a package, I'd like it to be 
minimally sufficient for others to
use in different contexts.

-Michael


Roger Bivand wrote:
> 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:
>
>> sessionInfo()
> 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
>
>> Thanks, -Michael
>>
>>
>>
>


-- 
Michael Friendly     Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA



More information about the R-sig-Geo mailing list