st_union crashes RStudio - bug?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

st_union crashes RStudio - bug?

Bertram Ostendorf
I am trying to dissolve internal boundaries using sf.  This crashes R in the example geojson map below, a simple map of Australia’s states and territories. I am using a polygon layer that processes fine in other GIS and also works fine using sp (casting to sp and using gUnaryUnion).  I am not after a workaround but I'd like to explore what's different in sf and why this particular layer causes problems.

My questions: Is this a bug in sf? Have others experienced similar issues using simple features?

Thanks

Bertram Ostendorf
Chair for Spatial Environmental Sciences
Director: Spatial Information Group
The University of Adelaide, AUSTRALIA 5005


# Here's my example layer and code:
# Note: Neither ArcGIS ‘repair geometry’ nor  ‘st_is_valid’ show any issues.
library(sf)
library(ggplot2)
# read Australia.geojson from dropbox, 15.5Mb
test <- st_read("https://www.dropbox.com/s/060c6lfijyx1e5v/Australia.geojson?dl=1")
st_is_valid(test)

# The next lines work fine, I added them to illustrate what works
ggplot(test) + geom_sf(aes(fill=STATE))
ACT <- test[test$STATE == 'ACT', ]
NSW <- test[test$STATE == 'NSW', ]
ACTandNSW <- test[test$STATE %in% c('NSW','ACT'), ]
noACT <- test[test$STATE != 'ACT', ]
noNSW <- test[test$STATE != 'NSW', ]
noACTandNSW <- test[!test$STATE %in% c('NSW','ACT'), ]
# st_union works ok for most subsets. But note that some internal boundaries are not removed.
ok <- st_union(ACT)
# donut polygons work fine
ok <- st_union(NSW)
# donut polygons (NSW) filled (ACT) work fine
ok <- st_union(ACTandNSW)
# all states except NSW work fine
ok <- st_union(noNSW)
# ok if both ACT and NSW are removed
ok <- st_union(noACTandNSW)
ggplot(ok) + geom_sf()

# Thing go pear-shaped if the hole is filled (ACT in NSW), but only if neighbours of the filled donut polygon are present.
# The two lines below stall R and eventually crash RStudio
crash <- st_union(test)
# Australia without its governing territory kills R
crash <- st_union(noACT)


> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
  [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252

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

other attached packages:
  [1] ggplot2_3.0.0 sf_0.6-3

loaded via a namespace (and not attached):
  [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5     units_0.6-0      tidyselect_0.2.4 munsell_0.5.0
[8] colorspace_1.3-2 R6_2.2.2         rlang_0.2.2      plyr_1.8.4       dplyr_0.7.6      tools_3.5.1      grid_3.5.1
[15] gtable_0.2.0     e1071_1.7-0      DBI_1.0.0        withr_2.1.2      class_7.3-14     digest_0.6.16    yaml_2.2.0
[22] lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2     crayon_1.3.4     bindrcpp_0.2.2   spData_0.2.9.3   purrr_0.2.5
[29] glue_1.3.0       compiler_3.5.1   pillar_1.3.0     scales_1.0.0     classInt_0.2-3   pkgconfig_2.0.2





        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: st_union crashes RStudio - bug?

Roman Luštrik
Crashes R or Rstudio?

Cheers,
Roman

On Fri, Sep 14, 2018 at 8:33 AM Bertram Ostendorf <
[hidden email]> wrote:

> I am trying to dissolve internal boundaries using sf.  This crashes R in
> the example geojson map below, a simple map of Australia’s states and
> territories. I am using a polygon layer that processes fine in other GIS
> and also works fine using sp (casting to sp and using gUnaryUnion).  I am
> not after a workaround but I'd like to explore what's different in sf and
> why this particular layer causes problems.
>
> My questions: Is this a bug in sf? Have others experienced similar issues
> using simple features?
>
> Thanks
>
> Bertram Ostendorf
> Chair for Spatial Environmental Sciences
> Director: Spatial Information Group
> The University of Adelaide, AUSTRALIA 5005
>
>
> # Here's my example layer and code:
> # Note: Neither ArcGIS ‘repair geometry’ nor  ‘st_is_valid’ show any
> issues.
> library(sf)
> library(ggplot2)
> # read Australia.geojson from dropbox, 15.5Mb
> test <- st_read("
> https://www.dropbox.com/s/060c6lfijyx1e5v/Australia.geojson?dl=1")
> st_is_valid(test)
>
> # The next lines work fine, I added them to illustrate what works
> ggplot(test) + geom_sf(aes(fill=STATE))
> ACT <- test[test$STATE == 'ACT', ]
> NSW <- test[test$STATE == 'NSW', ]
> ACTandNSW <- test[test$STATE %in% c('NSW','ACT'), ]
> noACT <- test[test$STATE != 'ACT', ]
> noNSW <- test[test$STATE != 'NSW', ]
> noACTandNSW <- test[!test$STATE %in% c('NSW','ACT'), ]
> # st_union works ok for most subsets. But note that some internal
> boundaries are not removed.
> ok <- st_union(ACT)
> # donut polygons work fine
> ok <- st_union(NSW)
> # donut polygons (NSW) filled (ACT) work fine
> ok <- st_union(ACTandNSW)
> # all states except NSW work fine
> ok <- st_union(noNSW)
> # ok if both ACT and NSW are removed
> ok <- st_union(noACTandNSW)
> ggplot(ok) + geom_sf()
>
> # Thing go pear-shaped if the hole is filled (ACT in NSW), but only if
> neighbours of the filled donut polygon are present.
> # The two lines below stall R and eventually crash RStudio
> crash <- st_union(test)
> # Australia without its governing territory kills R
> crash <- st_union(noACT)
>
>
> > sessionInfo()
> R version 3.5.1 (2018-07-02)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows >= 8 x64 (build 9200)
>
> Matrix products: default
>
> locale:
>   [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
>   LC_MONETARY=English_Australia.1252
> [4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252
>
> attached base packages:
>   [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
>   [1] ggplot2_3.0.0 sf_0.6-3
>
> loaded via a namespace (and not attached):
>   [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5
>  units_0.6-0      tidyselect_0.2.4 munsell_0.5.0
> [8] colorspace_1.3-2 R6_2.2.2         rlang_0.2.2      plyr_1.8.4
>  dplyr_0.7.6      tools_3.5.1      grid_3.5.1
> [15] gtable_0.2.0     e1071_1.7-0      DBI_1.0.0        withr_2.1.2
> class_7.3-14     digest_0.6.16    yaml_2.2.0
> [22] lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2     crayon_1.3.4
>  bindrcpp_0.2.2   spData_0.2.9.3   purrr_0.2.5
> [29] glue_1.3.0       compiler_3.5.1   pillar_1.3.0     scales_1.0.0
>  classInt_0.2-3   pkgconfig_2.0.2
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


--
In God we trust, all others bring data.

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: st_union crashes RStudio - bug?

Roger Bivand
Administrator
On Fri, 14 Sep 2018, Roman Luštrik wrote:

> Crashes R or Rstudio?

I guess the OP will get up sometime soon; of course one should always run
R in a console, not RStudio when reporting issues of this kind. Further,
one should run R -d gdb (if possible - see RW FAQ) to trap any important
information. I can see that crash <- st_union(noACT) is long-running, with
one thread at 100%, but no obvious memory issues (Fedora 28, sf 0.6-3,
GEOS 3.7.0). It would further make sense to go the sp/rgeos route to see
if it is data+GEOS or that the behavious is R-implementation dependent.

Roger

>
> Cheers,
> Roman
>
> On Fri, Sep 14, 2018 at 8:33 AM Bertram Ostendorf <
> [hidden email]> wrote:
>
>> I am trying to dissolve internal boundaries using sf.  This crashes R in
>> the example geojson map below, a simple map of Australia’s states and
>> territories. I am using a polygon layer that processes fine in other GIS
>> and also works fine using sp (casting to sp and using gUnaryUnion).  I am
>> not after a workaround but I'd like to explore what's different in sf and
>> why this particular layer causes problems.
>>
>> My questions: Is this a bug in sf? Have others experienced similar issues
>> using simple features?
>>
>> Thanks
>>
>> Bertram Ostendorf
>> Chair for Spatial Environmental Sciences
>> Director: Spatial Information Group
>> The University of Adelaide, AUSTRALIA 5005
>>
>>
>> # Here's my example layer and code:
>> # Note: Neither ArcGIS ‘repair geometry’ nor  ‘st_is_valid’ show any
>> issues.
>> library(sf)
>> library(ggplot2)
>> # read Australia.geojson from dropbox, 15.5Mb
>> test <- st_read("
>> https://www.dropbox.com/s/060c6lfijyx1e5v/Australia.geojson?dl=1")
>> st_is_valid(test)
>>
>> # The next lines work fine, I added them to illustrate what works
>> ggplot(test) + geom_sf(aes(fill=STATE))
>> ACT <- test[test$STATE == 'ACT', ]
>> NSW <- test[test$STATE == 'NSW', ]
>> ACTandNSW <- test[test$STATE %in% c('NSW','ACT'), ]
>> noACT <- test[test$STATE != 'ACT', ]
>> noNSW <- test[test$STATE != 'NSW', ]
>> noACTandNSW <- test[!test$STATE %in% c('NSW','ACT'), ]
>> # st_union works ok for most subsets. But note that some internal
>> boundaries are not removed.
>> ok <- st_union(ACT)
>> # donut polygons work fine
>> ok <- st_union(NSW)
>> # donut polygons (NSW) filled (ACT) work fine
>> ok <- st_union(ACTandNSW)
>> # all states except NSW work fine
>> ok <- st_union(noNSW)
>> # ok if both ACT and NSW are removed
>> ok <- st_union(noACTandNSW)
>> ggplot(ok) + geom_sf()
>>
>> # Thing go pear-shaped if the hole is filled (ACT in NSW), but only if
>> neighbours of the filled donut polygon are present.
>> # The two lines below stall R and eventually crash RStudio
>> crash <- st_union(test)
>> # Australia without its governing territory kills R
>> crash <- st_union(noACT)
>>
>>
>>> sessionInfo()
>> R version 3.5.1 (2018-07-02)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>> Running under: Windows >= 8 x64 (build 9200)
>>
>> Matrix products: default
>>
>> locale:
>>   [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
>>   LC_MONETARY=English_Australia.1252
>> [4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252
>>
>> attached base packages:
>>   [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>>   [1] ggplot2_3.0.0 sf_0.6-3
>>
>> loaded via a namespace (and not attached):
>>   [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5
>>  units_0.6-0      tidyselect_0.2.4 munsell_0.5.0
>> [8] colorspace_1.3-2 R6_2.2.2         rlang_0.2.2      plyr_1.8.4
>>  dplyr_0.7.6      tools_3.5.1      grid_3.5.1
>> [15] gtable_0.2.0     e1071_1.7-0      DBI_1.0.0        withr_2.1.2
>> class_7.3-14     digest_0.6.16    yaml_2.2.0
>> [22] lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2     crayon_1.3.4
>>  bindrcpp_0.2.2   spData_0.2.9.3   purrr_0.2.5
>> [29] glue_1.3.0       compiler_3.5.1   pillar_1.3.0     scales_1.0.0
>>  classInt_0.2-3   pkgconfig_2.0.2
>>
>>
>>
>>
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> 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; e-mail: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: st_union crashes RStudio - bug?

Roger Bivand
Administrator
(from an airport)

> crash <- st_union(noACT)

completed without error, test also passes. Your problem is not general

There is absolutely no need to use ggplot to display the geometries, by the way.

plot(st_geometry(crash))

shows errant partial boundaries, probably caused by the default precision model and geojson's character representation of numbers.

Roger

Roger Bivand
Norwegian School of Economics
Bergen, Norway




On Fri, Sep 14, 2018 at 7:00 PM +0200, "Roger Bivand" <[hidden email]<mailto:[hidden email]>> wrote:


On Fri, 14 Sep 2018, Roman Luštrik wrote:

> Crashes R or Rstudio?

I guess the OP will get up sometime soon; of course one should always run
R in a console, not RStudio when reporting issues of this kind. Further,
one should run R -d gdb (if possible - see RW FAQ) to trap any important
information. I can see that crash <- st_union(noACT) is long-running, with
one thread at 100%, but no obvious memory issues (Fedora 28, sf 0.6-3,
GEOS 3.7.0). It would further make sense to go the sp/rgeos route to see
if it is data+GEOS or that the behavious is R-implementation dependent.

Roger

>
> Cheers,
> Roman
>
> On Fri, Sep 14, 2018 at 8:33 AM Bertram Ostendorf <
> [hidden email]> wrote:
>
>> I am trying to dissolve internal boundaries using sf.  This crashes R in
>> the example geojson map below, a simple map of Australia’s states and
>> territories. I am using a polygon layer that processes fine in other GIS
>> and also works fine using sp (casting to sp and using gUnaryUnion).  I am
>> not after a workaround but I'd like to explore what's different in sf and
>> why this particular layer causes problems.
>>
>> My questions: Is this a bug in sf? Have others experienced similar issues
>> using simple features?
>>
>> Thanks
>>
>> Bertram Ostendorf
>> Chair for Spatial Environmental Sciences
>> Director: Spatial Information Group
>> The University of Adelaide, AUSTRALIA 5005
>>
>>
>> # Here's my example layer and code:
>> # Note: Neither ArcGIS ‘repair geometry’ nor  ‘st_is_valid’ show any
>> issues.
>> library(sf)
>> library(ggplot2)
>> # read Australia.geojson from dropbox, 15.5Mb
>> test <- st_read("
>> https://www.dropbox.com/s/060c6lfijyx1e5v/Australia.geojson?dl=1")
>> st_is_valid(test)
>>
>> # The next lines work fine, I added them to illustrate what works
>> ggplot(test) + geom_sf(aes(fill=STATE))
>> ACT <- test[test$STATE == 'ACT', ]
>> NSW <- test[test$STATE == 'NSW', ]
>> ACTandNSW <- test[test$STATE %in% c('NSW','ACT'), ]
>> noACT <- test[test$STATE != 'ACT', ]
>> noNSW <- test[test$STATE != 'NSW', ]
>> noACTandNSW <- test[!test$STATE %in% c('NSW','ACT'), ]
>> # st_union works ok for most subsets. But note that some internal
>> boundaries are not removed.
>> ok <- st_union(ACT)
>> # donut polygons work fine
>> ok <- st_union(NSW)
>> # donut polygons (NSW) filled (ACT) work fine
>> ok <- st_union(ACTandNSW)
>> # all states except NSW work fine
>> ok <- st_union(noNSW)
>> # ok if both ACT and NSW are removed
>> ok <- st_union(noACTandNSW)
>> ggplot(ok) + geom_sf()
>>
>> # Thing go pear-shaped if the hole is filled (ACT in NSW), but only if
>> neighbours of the filled donut polygon are present.
>> # The two lines below stall R and eventually crash RStudio
>> crash <- st_union(test)
>> # Australia without its governing territory kills R
>> crash <- st_union(noACT)
>>
>>
>>> sessionInfo()
>> R version 3.5.1 (2018-07-02)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>> Running under: Windows >= 8 x64 (build 9200)
>>
>> Matrix products: default
>>
>> locale:
>>   [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
>>   LC_MONETARY=English_Australia.1252
>> [4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252
>>
>> attached base packages:
>>   [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>>   [1] ggplot2_3.0.0 sf_0.6-3
>>
>> loaded via a namespace (and not attached):
>>   [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5
>>  units_0.6-0      tidyselect_0.2.4 munsell_0.5.0
>> [8] colorspace_1.3-2 R6_2.2.2         rlang_0.2.2      plyr_1.8.4
>>  dplyr_0.7.6      tools_3.5.1      grid_3.5.1
>> [15] gtable_0.2.0     e1071_1.7-0      DBI_1.0.0        withr_2.1.2
>> class_7.3-14     digest_0.6.16    yaml_2.2.0
>> [22] lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2     crayon_1.3.4
>>  bindrcpp_0.2.2   spData_0.2.9.3   purrr_0.2.5
>> [29] glue_1.3.0       compiler_3.5.1   pillar_1.3.0     scales_1.0.0
>>  classInt_0.2-3   pkgconfig_2.0.2
>>
>>
>>
>>
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> 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; e-mail: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: st_union crashes RStudio - bug?

Roger Bivand
Administrator
The in-flight analysis shows that the precision model interacts with the
geojson text representation of coordinates. I tried to use st_precision
without success. Using:

library(rgdal)
library(rgeos)
test1 <- readOGR("Australia.geojson")
setScale(4e+4)
crash1 <- gUnaryUnion(test1)
plot(crash1)
length(slot(slot(crash1, "polygons")[[1]], "Polygons"))
areas <- sapply(slot(slot(crash1, "polygons")[[1]], "Polygons"), slot,
"area")
head(sort(areas), n=10)
which(areas < 5e-8)
Pols <- slot(slot(crash1, "polygons")[[1]], "Polygons")
Pols1 <- Pols[-which(areas < 5e-8)]
slot(slot(crash1, "polygons")[[1]], "Polygons") <- Pols1
plot(crash1)

and changing scale to 4e+4 in rgeos notation, most of the remnant boundary
artefacts are removed. You can even remove the three dots in south-east
Australia. So: if you want to operations other than visualisation, avoid
geojson. If you can't avoid geojson, don't be surprised by topological
issues. Further, do use a vector representation suited to your purpose -
this one has far too much detail.

Roger

PS. Not tried on Windows - can someone please check that this doesn't
misbehave on the OP's platform?

On Fri, 14 Sep 2018, Roger Bivand wrote:

> (from an airport)
>
>> crash <- st_union(noACT)
>
> completed without error, test also passes. Your problem is not general
>
> There is absolutely no need to use ggplot to display the geometries, by
> the way.
>
> plot(st_geometry(crash))
>
> shows errant partial boundaries, probably caused by the default
> precision model and geojson's character representation of numbers.
>
> Roger
>
> Roger Bivand
> Norwegian School of Economics
> Bergen, Norway
>
>
>
>
> On Fri, Sep 14, 2018 at 7:00 PM +0200, "Roger Bivand" <[hidden email]<mailto:[hidden email]>> wrote:
>
>
> On Fri, 14 Sep 2018, Roman Luštrik wrote:
>
>> Crashes R or Rstudio?
>
> I guess the OP will get up sometime soon; of course one should always run
> R in a console, not RStudio when reporting issues of this kind. Further,
> one should run R -d gdb (if possible - see RW FAQ) to trap any important
> information. I can see that crash <- st_union(noACT) is long-running, with
> one thread at 100%, but no obvious memory issues (Fedora 28, sf 0.6-3,
> GEOS 3.7.0). It would further make sense to go the sp/rgeos route to see
> if it is data+GEOS or that the behavious is R-implementation dependent.
>
> Roger
>
>>
>> Cheers,
>> Roman
>>
>> On Fri, Sep 14, 2018 at 8:33 AM Bertram Ostendorf <
>> [hidden email]> wrote:
>>
>>> I am trying to dissolve internal boundaries using sf.  This crashes R in
>>> the example geojson map below, a simple map of Australia’s states and
>>> territories. I am using a polygon layer that processes fine in other GIS
>>> and also works fine using sp (casting to sp and using gUnaryUnion).  I am
>>> not after a workaround but I'd like to explore what's different in sf and
>>> why this particular layer causes problems.
>>>
>>> My questions: Is this a bug in sf? Have others experienced similar issues
>>> using simple features?
>>>
>>> Thanks
>>>
>>> Bertram Ostendorf
>>> Chair for Spatial Environmental Sciences
>>> Director: Spatial Information Group
>>> The University of Adelaide, AUSTRALIA 5005
>>>
>>>
>>> # Here's my example layer and code:
>>> # Note: Neither ArcGIS ‘repair geometry’ nor  ‘st_is_valid’ show any
>>> issues.
>>> library(sf)
>>> library(ggplot2)
>>> # read Australia.geojson from dropbox, 15.5Mb
>>> test <- st_read("
>>> https://www.dropbox.com/s/060c6lfijyx1e5v/Australia.geojson?dl=1")
>>> st_is_valid(test)
>>>
>>> # The next lines work fine, I added them to illustrate what works
>>> ggplot(test) + geom_sf(aes(fill=STATE))
>>> ACT <- test[test$STATE == 'ACT', ]
>>> NSW <- test[test$STATE == 'NSW', ]
>>> ACTandNSW <- test[test$STATE %in% c('NSW','ACT'), ]
>>> noACT <- test[test$STATE != 'ACT', ]
>>> noNSW <- test[test$STATE != 'NSW', ]
>>> noACTandNSW <- test[!test$STATE %in% c('NSW','ACT'), ]
>>> # st_union works ok for most subsets. But note that some internal
>>> boundaries are not removed.
>>> ok <- st_union(ACT)
>>> # donut polygons work fine
>>> ok <- st_union(NSW)
>>> # donut polygons (NSW) filled (ACT) work fine
>>> ok <- st_union(ACTandNSW)
>>> # all states except NSW work fine
>>> ok <- st_union(noNSW)
>>> # ok if both ACT and NSW are removed
>>> ok <- st_union(noACTandNSW)
>>> ggplot(ok) + geom_sf()
>>>
>>> # Thing go pear-shaped if the hole is filled (ACT in NSW), but only if
>>> neighbours of the filled donut polygon are present.
>>> # The two lines below stall R and eventually crash RStudio
>>> crash <- st_union(test)
>>> # Australia without its governing territory kills R
>>> crash <- st_union(noACT)
>>>
>>>
>>>> sessionInfo()
>>> R version 3.5.1 (2018-07-02)
>>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>> Running under: Windows >= 8 x64 (build 9200)
>>>
>>> Matrix products: default
>>>
>>> locale:
>>>   [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
>>>   LC_MONETARY=English_Australia.1252
>>> [4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252
>>>
>>> attached base packages:
>>>   [1] stats     graphics  grDevices utils     datasets  methods   base
>>>
>>> other attached packages:
>>>   [1] ggplot2_3.0.0 sf_0.6-3
>>>
>>> loaded via a namespace (and not attached):
>>>   [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5
>>>  units_0.6-0      tidyselect_0.2.4 munsell_0.5.0
>>> [8] colorspace_1.3-2 R6_2.2.2         rlang_0.2.2      plyr_1.8.4
>>>  dplyr_0.7.6      tools_3.5.1      grid_3.5.1
>>> [15] gtable_0.2.0     e1071_1.7-0      DBI_1.0.0        withr_2.1.2
>>> class_7.3-14     digest_0.6.16    yaml_2.2.0
>>> [22] lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2     crayon_1.3.4
>>>  bindrcpp_0.2.2   spData_0.2.9.3   purrr_0.2.5
>>> [29] glue_1.3.0       compiler_3.5.1   pillar_1.3.0     scales_1.0.0
>>>  classInt_0.2-3   pkgconfig_2.0.2
>>>
>>>
>>>
>>>
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email]
>>> 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; e-mail: [hidden email]
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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; e-mail: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway