[R-sig-Geo] Problems with rbind(list(), makeUniqueIDs=T)

Edzer Pebesma edzer.pebesma at uni-muenster.de
Fri Jul 22 23:53:50 CEST 2016


The correct call to rbind would be

mm = rbind(m[[1]], m[[2]], m[[3]], makeUniqueIDs=T)

with sp on CRAN this doesn't work; with the version on github it does.

An alternative with sp from CRAN is to make the IDs unique by hand:

spChFIDs(m[[1]]) <- paste0("A", seq(length(m[[1]])))
spChFIDs(m[[2]]) <- paste0("B", seq(length(m[[2]])))
spChFIDs(m[[3]]) <- paste0("C", seq(length(m[[3]])))
mm = rbind(m[[1]], m[[2]], m[[3]])


On 22/07/16 22:55, Bacou, Melanie wrote:
> Hi,
> I'm getting weird results trying to rbind a list of
> SpatialPolygonsDataFrames with R 3.2.1 and raster 2.5.8. I believe the
> code below used to merge all 3 country boundaries, but instead I now get
> a list with 6 elements (incl. 3 logical TRUE). Am I doing something wrong?
> 
> Thx, --Mel.
> 
>> library(raster)
>> m <- lapply(c("TZA", "UGA", "GHA"), function(x) getData("GADM",
> country=x, level=1))
>> m <- rbind(m, makeUniqueIDs=T)
>> sapply(m, class)
> [1] "SpatialPolygonsDataFrame" "logical" "SpatialPolygonsDataFrame"
> [4] "logical"                  "SpatialPolygonsDataFrame" "logical"
> 
>> sessionInfo()
> R version 3.2.1 (2015-06-18)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
> 
> locale:
> [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods base
> 
> other attached packages:
> [1] raster_2.5-8 sp_1.2-3     rj_2.0.5-2
> 
> loaded via a namespace (and not attached):
> [1] rj.gd_2.0.0-1   Rcpp_0.12.6     grid_3.2.1 lattice_0.20-33
> 

-- 
Edzer Pebesma
Institute for Geoinformatics  (ifgi),  University of Münster
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers & Geosciences:   http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160722/110e6c76/attachment.bin>


More information about the R-sig-Geo mailing list