## ## poly_sudipto.R -- improved and generalized version of poly.R ## written by Sudipto Banerjee and Joao Monteiro, 2010 ## ## Notes from the author: ## ## sp2WB is a part of the maptools R package written primarily by Nicholas ## J. Lewin-Koh and Roger Bivand, with a host other contributors. sp2WB was ## specifically written by Virgilio Gomez Rubio, partly derived from ## earlier code by Thomas Jagger. ## ## I have been using sp2WB with ESRI shapefiles for quite some time now and ## they work well. The code below was written by Joao Monteiro, ## with a bit of input from me, to export maps from the "maps" database in ## R into WinBUGS. ############################################## library(maps) library(maptools) minnesota_county <- map('county', 'minnesota', fill=TRUE, plot = F) minnesota_county$names <- sapply(strsplit(minnesota_county$names, ","), function(x) paste(x[1],",",paste(strsplit(x[2], " ")[[1]], collapse =""),sep="")) IDs <- sapply(strsplit(minnesota_county$names, ","), function(x) x[2]) minnesota_countySP <- map2SpatialPolygons(minnesota_county, IDs=IDs, proj4string=CRS("+proj=longlat +datum=wgs84")) sp2WB(minnesota_countySP, file="mn_bugs.txt") ####################################################