[R-sig-Geo] unionSpatialPolygons from the command-line

Roger Bivand Roger.Bivand at nhh.no
Fri Apr 8 13:15:27 CEST 2016


On Thu, 7 Apr 2016, Stachelek, Joseph wrote:

> Hello,
>
> I am trying to call "maptools::unionSpatialPolygons()" from the command-line. To illustrate the problem, I can call example(unionSpatialPolygons) from an interactive session but running an R script (testmaptools.R) containing:
>
> `library(maptools)`
> `example(unionSpatialPolygons)`
>

With R --vanilla < testmaptools.R

and adding print(sessionInfo()) to the script, we see:

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

and it runs correctly. With

Rscript testmaptools.R

we see:

attached base packages:
[1] stats     graphics  grDevices utils     datasets  base

The script runs using Rscript if library(methods) is added as the first 
line. This issue has been seen elsewhere recently in another context, we 
don't know why.

Hope this clarifies,

Roger

> yields:
>
> `$ Rscript testmaptools.R`
>> WARNING: ignoring environment value of R_HOME
>> Loading required package: sp
>> Checking rgeos availability: TRUE
>
>> unnSpP> if (rgeosStatus()) {
>> unnSpP+ nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
>> unnSpP+  proj4string=CRS("+proj=longlat +datum=NAD27"))
>> unnSpP+ lps <- coordinates(nc1)
>> unnSpP+ ID <- cut(lps[,1], quantile(lps[,1]), include.lowest=TRUE)
>> unnSpP+ reg4 <- unionSpatialPolygons(nc1, ID)
>> unnSpP+ row.names(reg4)
>> unnSpP+ }
>> Error in rgeos::gUnaryUnion(spgeom = SpP, id = IDs) :
>>   Invalid geometry, may only be applied to polygons
>> Calls: example ... eval -> eval -> unionSpatialPolygons -> <Anonymous>
>> Execution halted
>
> Is this not possible?
>
> Thank you,
>
> Joseph Stachelek
>
>
> We value your opinion. Please take a few minutes to shar...{{dropped:8}}
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412



More information about the R-sig-Geo mailing list